diff --git a/src/App.vue b/src/App.vue index e853f392..f215f248 100644 --- a/src/App.vue +++ b/src/App.vue @@ -62,7 +62,7 @@ export default { const App = this; (async function() { - const locale = App.getPreferenceString("hl", "en"); + const locale = App.getPreferenceString("hl", App.defaultLangage); if (window.i18n.global.locale.value !== locale) { if (!window.i18n.global.availableLocales.includes(locale)) { const messages = await import("@/locales/" + locale + ".json").then(module => module.default); diff --git a/src/components/Preferences.vue b/src/components/Preferences.vue index 37822521..8364938c 100644 --- a/src/components/Preferences.vue +++ b/src/components/Preferences.vue @@ -352,7 +352,7 @@ export default { this.showComments = this.getPreferenceBoolean("comments", true); this.minimizeDescription = this.getPreferenceBoolean("minimizeDescription", false); this.watchHistory = this.getPreferenceBoolean("watchHistory", false); - this.selectedLanguage = this.getPreferenceString("hl", "en"); + this.selectedLanguage = this.getPreferenceString("hl", this.defaultLangage); this.enabledCodecs = this.getPreferenceString("enabledCodecs", "av1,vp9,avc").split(","); this.disableLBRY = this.getPreferenceBoolean("disableLBRY", false); this.proxyLBRY = this.getPreferenceBoolean("proxyLBRY", false); @@ -377,7 +377,7 @@ export default { if ( this.getPreferenceString("theme", "dark") !== this.selectedTheme || this.getPreferenceBoolean("watchHistory", false) != this.watchHistory || - this.getPreferenceString("hl", "en") !== this.selectedLanguage || + this.getPreferenceString("hl", this.defaultLangage) !== this.selectedLanguage || this.getPreferenceString("enabledCodecs", "av1,vp9,avc") !== this.enabledCodecs.join(",") ) shouldReload = true; diff --git a/src/main.js b/src/main.js index 3c9c57a9..677f040b 100644 --- a/src/main.js +++ b/src/main.js @@ -210,6 +210,18 @@ const mixin = { return false; } }, + defaultLangage() { + const languages = window.navigator.languages; + for (let i = 0; i < languages.length; i++) { + try { + require("@/locales/" + languages[i] + ".json"); + return languages[i]; + } catch { + continue; + } + } + return "en"; + }, }, };