From e7f9a40eeb8f27299351c767874fbf21bc1e92fa Mon Sep 17 00:00:00 2001 From: Duwibi <86431918+Duwibi@users.noreply.github.com> Date: Sun, 1 Jun 2025 01:53:52 +0300 Subject: [PATCH] Fix Translations showing as untranslated keys (#983) ## Description: Fixes translations showing as untranslated keys ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: Nikola123 --- src/client/LangSelector.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/client/LangSelector.ts b/src/client/LangSelector.ts index adee86edf..27b7f9399 100644 --- a/src/client/LangSelector.ts +++ b/src/client/LangSelector.ts @@ -78,10 +78,18 @@ export class LangSelector extends LitElement { }); } + private getClosestSupportedLang(lang: string): string { + if (!lang) return "en"; + if (lang in this.languageMap) return lang; + const base = lang.split("-")[0]; + if (base in this.languageMap) return base; + return "en"; + } + private async initializeLanguage() { - const locale = new Intl.Locale(navigator.language); - const defaultLang = locale.language; - const userLang = localStorage.getItem("lang") || defaultLang; + const browserLocale = navigator.language; + const savedLang = localStorage.getItem("lang"); + const userLang = this.getClosestSupportedLang(savedLang || browserLocale); this.defaultTranslations = await this.loadLanguage("en"); this.translations = await this.loadLanguage(userLang);