fix: Localisation-matching algorithm missing some edgecase (#4692)

This commit is contained in:
Frank Elsinga
2024-04-21 14:23:34 +02:00
committed by GitHub
parent e797abd108
commit add5c128ce
2 changed files with 48 additions and 19 deletions

View File

@@ -63,9 +63,22 @@ const rtlLangs = [ "fa", "ar-SY", "ur" ];
* @returns {string} the locale that should be displayed
*/
export function currentLocale() {
const potentialLocales = [ localStorage.locale, navigator.language, navigator.language.substring(0, 2), ...navigator.languages ];
const availableLocales = potentialLocales.filter(l => languageList[l]);
return availableLocales[0] || "en";
for (const locale of [ localStorage.locale, navigator.language, ...navigator.languages ]) {
// localstorage might not have a value or there might not be a language in `navigator.language`
if (!locale) {
continue;
}
if (locale in messages) {
return locale;
}
// some locales are further specified such as "en-US".
// If we only have a generic locale for this, we can use it too
const genericLocale = locale.split("-")[0];
if (genericLocale in messages) {
return genericLocale;
}
}
return "en";
}
export const localeDirection = () => {