Sunshine/src_assets/common/assets/web/locale.js
ReenigneArcher 87774333f3
feat(i18n): add ui localization (#2279)
Co-authored-by: TheElixZammuto <6505622+TheElixZammuto@users.noreply.github.com>
2024-03-22 19:54:12 -04:00

28 lines
789 B
JavaScript

import {createI18n} from "vue-i18n";
// Import only the fallback language files
import en from './public/assets/locale/en.json'
export default async function() {
let r = await (await fetch("/api/configLocale")).json();
let locale = r.locale ?? "en";
document.querySelector('html').setAttribute('lang', locale);
let messages = {
en
};
try {
if (locale !== 'en') {
let r = await (await fetch(`/assets/locale/${locale}.json`)).json();
messages[locale] = r;
}
} catch (e) {
console.error("Failed to download translations", e);
}
const i18n = createI18n({
locale: locale, // set locale
fallbackLocale: 'en', // set fallback locale
messages: messages
})
return i18n;
}