Use LocaleMatcher to resolve system preferred locales

This commit is contained in:
Jamie Kyle 2023-04-17 12:26:57 -07:00 committed by GitHub
parent 68ae25f5cd
commit cdc68d1c34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 224 additions and 48 deletions

View file

@ -0,0 +1,46 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { load } from '../../../app/locale';
import type { LoggerType } from '../../types/Logging';
const logger: Pick<LoggerType, 'info' | 'warn'> = {
info(..._args: Array<unknown>) {
// noop
},
warn(..._args: Array<unknown>) {
throw new Error(String(_args));
},
};
describe('locale', async () => {
describe('load', () => {
it('resolves expected locales correctly', async () => {
async function testCase(
preferredSystemLocales: Array<string>,
expectedLocale: string
) {
const actualLocale = await load({ preferredSystemLocales, logger });
assert.strictEqual(actualLocale.name, expectedLocale);
}
// Basic tests
await testCase(['en'], 'en');
await testCase(['es'], 'es');
await testCase(['fr', 'hk'], 'fr');
await testCase(['fr-FR', 'hk'], 'fr');
await testCase(['fa-UK'], 'fa-IR');
await testCase(['an', 'fr-FR'], 'fr'); // If we ever add support for Aragonese, this test will fail.
// Specific cases we want to ensure work as expected
await testCase(['zh-Hant-TW'], 'zh-TW');
await testCase(['zh-Hant-HK'], 'zh-HK');
await testCase(['zh'], 'zh-CN');
await testCase(['yue'], 'yue');
await testCase(['ug'], 'ug');
await testCase(['nn', 'nb'], 'nb');
await testCase(['es-419'], 'es');
});
});
});

View file

@ -202,9 +202,6 @@ describe('createTemplate', () => {
info(_arg: unknown) {
// noop
},
error(arg: unknown) {
throw new Error(String(arg));
},
warn(arg: unknown) {
throw new Error(String(arg));
},