From 1dbd1e375be793f180878f55e7a603310e02f5ba Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 26 Jun 2022 02:53:06 +0100 Subject: [PATCH] Fix default language detection. Closes #1118 Closes #743 --- src/App.vue | 3 ++- src/components/PreferencesPage.vue | 6 +++--- src/main.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index a19259d7..59cc3f29 100644 --- a/src/App.vue +++ b/src/App.vue @@ -46,7 +46,8 @@ export default { const App = this; (async function () { - const locale = App.getPreferenceString("hl", App.defaultLangage); + const defaultLang = await App.defaultLangage; + const locale = App.getPreferenceString("hl", defaultLang); if (locale !== App.TimeAgoConfig.locale) { const localeTime = await import( "./../node_modules/javascript-time-ago/locale/" + locale + ".json" diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index e7c7f57e..d4c3e634 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -357,7 +357,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", this.defaultLangage); + this.selectedLanguage = this.getPreferenceString("hl", await this.defaultLangage); this.enabledCodecs = this.getPreferenceString("enabledCodecs", "vp9,avc").split(","); this.disableLBRY = this.getPreferenceBoolean("disableLBRY", false); this.proxyLBRY = this.getPreferenceBoolean("proxyLBRY", false); @@ -373,14 +373,14 @@ export default { } }, methods: { - onChange() { + async onChange() { if (this.testLocalStorage) { var shouldReload = false; if ( this.getPreferenceString("theme", "dark") !== this.selectedTheme || this.getPreferenceBoolean("watchHistory", false) != this.watchHistory || - this.getPreferenceString("hl", this.defaultLangage) !== this.selectedLanguage || + this.getPreferenceString("hl", await 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 37bc9250..ee3887fb 100644 --- a/src/main.js +++ b/src/main.js @@ -208,11 +208,11 @@ const mixin = { return false; } }, - defaultLangage() { + async defaultLangage() { const languages = window.navigator.languages; for (let i = 0; i < languages.length; i++) { try { - require("@/locales/" + languages[i] + ".json"); + await import("./locales/" + languages[i] + ".json"); return languages[i]; } catch { continue;