diff --git a/src/boot/i18n.js b/src/boot/i18n.js index b23b6d5fd..ede8f5114 100644 --- a/src/boot/i18n.js +++ b/src/boot/i18n.js @@ -1,6 +1,7 @@ import { boot } from 'quasar/wrappers'; import { createI18n } from 'vue-i18n'; import messages from 'src/i18n'; +import { locales } from 'src/i18n/handle'; const i18n = createI18n({ locale: navigator.language || navigator.userLanguage, @@ -12,8 +13,9 @@ const i18n = createI18n({ legacy: false, }); -export default boot(({ app }) => { +export default boot(async ({ app }) => { // Set i18n instance on app + await locales(); app.use(i18n); }); diff --git a/src/i18n/handle.js b/src/i18n/handle.js new file mode 100644 index 000000000..331b60b71 --- /dev/null +++ b/src/i18n/handle.js @@ -0,0 +1,17 @@ +const modules = import.meta.glob(`../pages/**/locale/**.yml`); +import translations from './index'; +const LOCALE_EXTENSION = '.yml'; + +export async function locales() { + for await (const module of Object.keys(modules)) { + const splittedFile = module.split('/'); + const lang = splittedFile.pop().split(LOCALE_EXTENSION)[0]; + const moduleFiles = splittedFile.join('/') + '/' + lang + LOCALE_EXTENSION; + import(moduleFiles).then((t) => { + Object.assign(translations[lang], t.default); + }); + } + return translations; +} + +export default translations; diff --git a/src/i18n/index.js b/src/i18n/index.js index 331ef914a..d94f77bb2 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -1,23 +1,11 @@ const files = import.meta.glob(`./locale/*.yml`); -const modules = import.meta.glob(`../pages/**/locale/en.yml`); const translations = {}; for (const file in files) { const lang = file.split('/').at(2).split('.')[0]; - import(file) - .then((t) => { - translations[lang] = t.default; - }) - .finally(() => { - for (const module in modules) { - const splittedFile = module.split('/'); - splittedFile.pop(); - const moduleFiles = splittedFile.join('/') + '/' + lang + '.yml'; - import(moduleFiles).then((t) => { - Object.assign(translations[lang], t.default); - }); - } - }); + import(file).then((t) => { + translations[lang] = t.default; + }); } export const localeEquivalence = { diff --git a/src/pages/Customer/locale/en.yml b/src/pages/Customer/locale/en.yml index 67bfa6622..6eb7cfa85 100644 --- a/src/pages/Customer/locale/en.yml +++ b/src/pages/Customer/locale/en.yml @@ -1,4 +1,4 @@ customerFilter: filter: - name: 'Name' - socialName: 'Social name' + name: Name + socialName: Social name diff --git a/src/pages/Customer/locale/es.yml b/src/pages/Customer/locale/es.yml index ec1981257..8fed37092 100644 --- a/src/pages/Customer/locale/es.yml +++ b/src/pages/Customer/locale/es.yml @@ -1,4 +1,4 @@ customerFilter: filter: - name: 'Nombre' - socialName: 'Razón Social' + name: Nombre + socialName: Razón Social