mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-18 20:24:36 -05:00
made sure that the i18n does use navigator.languages
instead of navigator.language
for automatic language detection (#4244)
This commit is contained in:
parent
458cdf9f9b
commit
7635ab54a0
14
src/i18n.js
14
src/i18n.js
@ -57,10 +57,16 @@ for (let lang in languageList) {
|
|||||||
|
|
||||||
const rtlLangs = [ "fa", "ar-SY", "ur" ];
|
const rtlLangs = [ "fa", "ar-SY", "ur" ];
|
||||||
|
|
||||||
export const currentLocale = () => localStorage.locale
|
/**
|
||||||
|| languageList[navigator.language] && navigator.language
|
* Find the best matching locale to display
|
||||||
|| languageList[navigator.language.substring(0, 2)] && navigator.language.substring(0, 2)
|
* If no locale can be matched, the default is "en"
|
||||||
|| "en";
|
* @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";
|
||||||
|
}
|
||||||
|
|
||||||
export const localeDirection = () => {
|
export const localeDirection = () => {
|
||||||
return rtlLangs.includes(currentLocale()) ? "rtl" : "ltr";
|
return rtlLangs.includes(currentLocale()) ? "rtl" : "ltr";
|
||||||
|
@ -4,9 +4,13 @@ describe("Test i18n.js", () => {
|
|||||||
|
|
||||||
it("currentLocale()", () => {
|
it("currentLocale()", () => {
|
||||||
const setLanguage = (language) => {
|
const setLanguage = (language) => {
|
||||||
Object.defineProperty(window.navigator, 'language', {
|
Object.defineProperty(window.navigator, 'language', {
|
||||||
value: language,
|
value: language,
|
||||||
writable: true
|
writable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(window.navigator, 'languages', {
|
||||||
|
value: [language],
|
||||||
|
writable: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setLanguage('en-EN');
|
setLanguage('en-EN');
|
||||||
@ -41,4 +45,4 @@ describe("Test i18n.js", () => {
|
|||||||
expect(currentLocale()).equal("zh-HK");
|
expect(currentLocale()).equal("zh-HK");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user