2023-01-10 07:18:45 +00:00
|
|
|
import { currentLocale } from "../../../src/i18n";
|
|
|
|
|
|
|
|
describe("Test i18n.js", () => {
|
|
|
|
|
|
|
|
it("currentLocale()", () => {
|
2024-04-21 12:23:34 +00:00
|
|
|
const setLanguages = (languages) => {
|
|
|
|
Object.defineProperty(navigator, 'language', {
|
|
|
|
value: languages[0],
|
2024-01-07 15:55:10 +00:00
|
|
|
writable: true
|
|
|
|
});
|
2024-04-21 12:23:34 +00:00
|
|
|
Object.defineProperty(navigator, 'languages', {
|
|
|
|
value: languages,
|
2024-01-07 15:55:10 +00:00
|
|
|
writable: true
|
2023-01-10 07:18:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['en-EN']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['zh-HK']);
|
2023-01-10 07:18:45 +00:00
|
|
|
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
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['zh-hk']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['en-US']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['ja-ZZ']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("ja");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['zz-ZZ']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['zz-ZZ']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['en-US', 'en', 'pl', 'ja']);
|
2023-01-10 07:18:45 +00:00
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
2024-04-21 12:23:34 +00:00
|
|
|
setLanguages(['en-US', 'pl', 'ja']);
|
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
|
|
|
setLanguages(['abc', 'en-US', 'pl', 'ja']);
|
|
|
|
expect(currentLocale()).equal("en");
|
|
|
|
|
|
|
|
setLanguages(['fil-PH', 'pl']);
|
|
|
|
expect(currentLocale()).equal("pl");
|
|
|
|
|
|
|
|
setLanguages(['shi-Latn-MA', 'pl']);
|
|
|
|
expect(currentLocale()).equal("pl");
|
|
|
|
|
|
|
|
setLanguages(['pl']);
|
|
|
|
localStorage.locale = "ja-ZZ";
|
|
|
|
expect(currentLocale()).equal("ja");
|
|
|
|
|
|
|
|
setLanguages(['pl']);
|
|
|
|
localStorage.locale = "invalid-lang";
|
|
|
|
expect(currentLocale()).equal("pl");
|
2023-01-10 07:18:45 +00:00
|
|
|
});
|
|
|
|
|
2024-01-07 15:55:10 +00:00
|
|
|
});
|