From 58e69da0c2e30a9a11327f4d1ecba92f97a53bd1 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 23 Sep 2021 23:57:26 +0100 Subject: [PATCH] Use user's system language by default. --- src/App.vue | 2 +- src/components/Preferences.vue | 4 ++-- src/main.js | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) 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"; + }, }, };