Merge pull request 'fix: refs #6425 fixed dev translations' (!294) from 6425-fixDevTranslations into dev
gitea/salix-front/pipeline/head This commit looks good Details
gitea/salix-front/pipeline/pr-dev This commit looks good Details

Reviewed-on: #294
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-04-16 12:35:36 +00:00
commit 892c5986c0
5 changed files with 20 additions and 26 deletions

View File

@ -1,7 +1,6 @@
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,
@ -13,9 +12,8 @@ const i18n = createI18n({
legacy: false,
});
export default boot(async ({ app }) => {
export default boot(({ app }) => {
// Set i18n instance on app
await locales();
app.use(i18n);
});

View File

@ -1,17 +0,0 @@
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;

View File

@ -1,10 +1,23 @@
const files = import.meta.glob(`./locale/*.yml`);
const modules = import.meta.glob(`../pages/**/locale/*.yml`);
const translations = {};
for (const file in files) {
const lang = file.split('/').at(2).split('.')[0];
import(file).then((t) => {
translations[lang] = t.default;
files[file]()
.then((g) => {
translations[lang] = g.default;
})
.finally(() => {
const actualLang = lang + '.yml';
for (const module in modules) {
if (!module.endsWith(actualLang)) continue;
modules[module]().then((t) => {
Object.assign(translations[lang], t.default);
})
}
});
}

View File

@ -1,4 +1,4 @@
customerFilter:
filter:
name: Name
socialName: Social name
name: 'Name'
socialName: 'Social name'

View File

@ -1,4 +1,4 @@
customerFilter:
filter:
name: Nombre
socialName: Razón Social
name: 'Nombre'
socialName: 'Razón Social'