mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-21 11:35:15 +08:00
fix: Localisation-matching algorithm missing some edgecase (#4692)
This commit is contained in:
19
src/i18n.js
19
src/i18n.js
@@ -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 = () => {
|
||||
|
Reference in New Issue
Block a user