Add function to load languages dynamically

This commit is contained in:
2026-05-19 21:05:09 +02:00
parent 2882f78990
commit 2eb187ec1a
2 changed files with 21 additions and 2 deletions
+17 -1
View File
@@ -24,4 +24,20 @@ export const i18n = createI18n({
locale: getCurrentLanguage(),
fallbackLocale: fallbackLocale,
messages: {}
});
});
const loadedLanguages = new Set();
export async function loadLanguage (locale) {
if (loadedLanguages.has(locale)) {
i18n.global.locale.value = locale;
return;
};
const messages = (await import(`./locales/${locale}.json`)).default;
i18n.global.setLocaleMessage(locale, messages);
i18n.global.locale.value = locale;
loadedLanguages.add(locale);
};