Files
BetiX/resources/js/i18n/index.ts
Dolo 0280278978
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
Initialer Laravel Commit für BetiX
2026-04-04 18:01:50 +02:00

44 lines
1.3 KiB
TypeScript

import { createI18n } from 'vue-i18n';
// Start with English synchronously to avoid FOUC; other locales lazy-loaded
async function loadLocaleMessages(locale: string) {
const norm = locale.replace('-', '_');
switch (norm) {
case 'de':
return (await import('./de.json')).default;
case 'es':
return (await import('./es.json')).default;
case 'pt_BR':
case 'pt-br':
return (await import('./pt_BR.json')).default;
case 'tr':
return (await import('./tr.json')).default;
case 'pl':
return (await import('./pl.json')).default;
default:
return (await import('./en.json')).default;
}
}
export const i18n = createI18n({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
messages: {},
});
export async function initI18n(startLocale: string) {
const msgs = await loadLocaleMessages(startLocale || 'en');
i18n.global.setLocaleMessage(startLocale || 'en', msgs);
i18n.global.locale.value = startLocale || 'en';
}
export async function setLocale(locale: string) {
const norm = locale.replace('-', '_');
if (!i18n.global.getLocaleMessage(norm) || Object.keys(i18n.global.getLocaleMessage(norm)).length === 0) {
const msgs = await loadLocaleMessages(norm);
i18n.global.setLocaleMessage(norm, msgs);
}
i18n.global.locale.value = norm;
}