mirror of https://github.com/louislam/uptime-kuma
Improve i18n language matching (#5939)
parent
5aeda2dab0
commit
072226bde2
19
src/i18n.js
19
src/i18n.js
|
@ -75,11 +75,20 @@ export function currentLocale() {
|
|||
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;
|
||||
// If the locale is a 2-letter code, we can try to find a regional variant
|
||||
// e.g. "fr" may not be in the messages, but "fr-FR" is
|
||||
if (locale.length === 2) {
|
||||
const regionalLocale = `${locale}-${locale.toUpperCase()}`;
|
||||
if (regionalLocale in messages) {
|
||||
return regionalLocale;
|
||||
}
|
||||
} else {
|
||||
// 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.slice(0, 2);
|
||||
if (genericLocale in messages) {
|
||||
return genericLocale;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "en";
|
||||
|
|
Loading…
Reference in New Issue