diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 96da6dd..387ce0e 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -42,6 +42,9 @@ const switchLanguage = function (lang) { const languageFlag = computed(() => { // `this` points to the component instance let lang = appGlobal.$i18n.locale.toLowerCase(); + if (!appGlobal.$i18n.availableLocales.includes(lang)) { + lang = appGlobal.$i18n.fallbackLocale; + } if (lang === "en") { lang = "us"; } diff --git a/frontend/src/lang/index.js b/frontend/src/lang/index.js index 0beda26..8b6c3a5 100644 --- a/frontend/src/lang/index.js +++ b/frontend/src/lang/index.js @@ -4,20 +4,16 @@ import ru from './translations/ru.json'; import en from './translations/en.json'; import {createI18n} from "vue-i18n"; -function getStoredLanguage() { - let initialLang = localStorage.getItem('wgLang'); - if (!initialLang) { - initialLang = "en" - } - return initialLang -} - // Create i18n instance with options const i18n = createI18n({ legacy: false, globalInjection: true, allowComposition: true, - locale: getStoredLanguage(), // set locale + locale: ( + localStorage.getItem('wgLang') + || (window && window.navigator && (window.navigator.userLanguage || window.navigator.language).split('-')[0]) + || 'en' + ), // set locale fallbackLocale: "en", // set fallback locale messages: { "de": de, @@ -26,4 +22,4 @@ const i18n = createI18n({ } }); -export default i18n \ No newline at end of file +export default i18n