fix: Potential missmatch between selected language preference and browser language preference

This commit is contained in:
Tom Moor
2023-05-17 20:23:39 -04:00
parent 9b257e9593
commit a19c19985e
3 changed files with 15 additions and 13 deletions

View File

@@ -12,12 +12,14 @@ export function changeLanguage(
toLanguageString: string | null | undefined, toLanguageString: string | null | undefined,
i18n: i18n i18n: i18n
) { ) {
if (toLanguageString && i18n.language !== toLanguageString) { const locale = toLanguageString
? unicodeCLDRtoBCP47(toLanguageString)
: undefined;
if (locale && i18n.languages[0] !== locale) {
// Languages are stored in en_US format in the database, however the // Languages are stored in en_US format in the database, however the
// frontend translation framework (i18next) expects en-US // frontend translation framework (i18next) expects en-US
const locale = unicodeCLDRtoBCP47(toLanguageString);
i18n.changeLanguage(locale); i18n.changeLanguage(locale);
Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]); Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]);
} }
} }

View File

@@ -104,9 +104,9 @@
"gemoji": "6.x", "gemoji": "6.x",
"glob": "^8.1.0", "glob": "^8.1.0",
"http-errors": "2.0.0", "http-errors": "2.0.0",
"i18next": "^22.4.8", "i18next": "^22.4.15",
"i18next-fs-backend": "^2.1.1", "i18next-fs-backend": "^2.1.1",
"i18next-http-backend": "^2.1.1", "i18next-http-backend": "^2.2.0",
"inline-css": "^4.0.2", "inline-css": "^4.0.2",
"invariant": "^2.2.4", "invariant": "^2.2.4",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",

View File

@@ -7587,10 +7587,10 @@ i18next-fs-backend@^2.1.1:
resolved "https://registry.yarnpkg.com/i18next-fs-backend/-/i18next-fs-backend-2.1.1.tgz#07c6393be856c5a398e3dfc1257bf8439841cd89" resolved "https://registry.yarnpkg.com/i18next-fs-backend/-/i18next-fs-backend-2.1.1.tgz#07c6393be856c5a398e3dfc1257bf8439841cd89"
integrity sha512-FTnj+UmNgT3YRml5ruRv0jMZDG7odOL/OP5PF5mOqvXud2vHrPOOs68Zdk6iqzL47cnnM0ZVkK2BAvpFeDJToA== integrity sha512-FTnj+UmNgT3YRml5ruRv0jMZDG7odOL/OP5PF5mOqvXud2vHrPOOs68Zdk6iqzL47cnnM0ZVkK2BAvpFeDJToA==
i18next-http-backend@^2.1.1: i18next-http-backend@^2.2.0:
version "2.1.1" version "2.2.0"
resolved "https://registry.yarnpkg.com/i18next-http-backend/-/i18next-http-backend-2.1.1.tgz#72a21d61c2e96eea9ad45ba1b9dd0090e119709a" resolved "https://registry.yarnpkg.com/i18next-http-backend/-/i18next-http-backend-2.2.0.tgz#f77c06dc8e766c7588bb38da2f5fa0614ba67b3f"
integrity sha512-jByfUCDVgQ8+/Wens7queQhYYvMcGTW/lR4IJJNEDDXnmqjLrwi8ubXKpmp76/JIWEZHffNdWqnxFJcTVGeaOw== integrity sha512-Z4sM7R6tzdLknSPER9GisEBxKPg5FkI07UrQniuroZmS15PHQrcCPLyuGKj8SS68tf+O2aEDYSUnmy1TZqZSbw==
dependencies: dependencies:
cross-fetch "3.1.5" cross-fetch "3.1.5"
@@ -7620,10 +7620,10 @@ i18next-parser@^7.9.0:
vinyl-fs "^3.0.2" vinyl-fs "^3.0.2"
vue-template-compiler "^2.6.11" vue-template-compiler "^2.6.11"
i18next@^22.0.4, i18next@^22.4.8: i18next@^22.0.4, i18next@^22.4.15:
version "22.4.8" version "22.4.15"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-22.4.8.tgz#7a3c5d26a93e8e5f32eee07b58484e2f721fb45b" resolved "https://registry.yarnpkg.com/i18next/-/i18next-22.4.15.tgz#951882b751872994f8502b5a6ef6f796e6a7d7f8"
integrity sha512-XSOy17ZWqflOiJRYE/dzv6vDle2Se32dnHREHb93UnZzZ1+UnvQ8yKtt1fpNL3zvXz5AwCqqixrtTVZmRetaiQ== integrity sha512-yYudtbFrrmWKLEhl6jvKUYyYunj4bTBCe2qIUYAxbXoPusY7YmdwPvOE6fx6UIfWvmlbCWDItr7wIs8KEBZ5Zg==
dependencies: dependencies:
"@babel/runtime" "^7.20.6" "@babel/runtime" "^7.20.6"