mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-09-08 02:12:10 +00:00
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import { currentLocale } from "../../../src/i18n";
|
|
|
|
describe("Test i18n.js", () => {
|
|
|
|
it("currentLocale()", () => {
|
|
const setLanguage = (language) => {
|
|
Object.defineProperty(window.navigator, 'language', {
|
|
value: language,
|
|
writable: true
|
|
});
|
|
Object.defineProperty(window.navigator, 'languages', {
|
|
value: [language],
|
|
writable: true
|
|
});
|
|
}
|
|
setLanguage('en-EN');
|
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguage('zh-HK');
|
|
expect(currentLocale()).equal("zh-HK");
|
|
|
|
// Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
|
|
setLanguage('zh-hk');
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguage('en-US');
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguage('ja-ZZ');
|
|
expect(currentLocale()).equal("ja");
|
|
|
|
setLanguage('zz-ZZ');
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguage('zz-ZZ');
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguage('en');
|
|
localStorage.locale = "en";
|
|
expect(currentLocale()).equal("en");
|
|
|
|
localStorage.locale = "zh-HK";
|
|
expect(currentLocale()).equal("zh-HK");
|
|
});
|
|
|
|
});
|