|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import { langs } from '$lib/constants';
|
|
|
|
|
import messages from '$lib/i18n/en.json';
|
|
|
|
|
import { getClosestAvailableLocale } from '$lib/utils/i18n';
|
|
|
|
|
import { exec as execCallback } from 'node:child_process';
|
|
|
|
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
|
|
|
import { promisify } from 'node:util';
|
|
|
|
|
@ -52,4 +53,30 @@ describe('i18n', () => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getClosestAvailableLocale', () => {
|
|
|
|
|
const allLocales = ['ar', 'bg', 'en', 'en-US', 'en-DE', 'zh-Hans', 'zh-Hans-HK'];
|
|
|
|
|
|
|
|
|
|
it('returns undefined on mismatch', () => {
|
|
|
|
|
expect(getClosestAvailableLocale([], allLocales)).toBeUndefined();
|
|
|
|
|
expect(getClosestAvailableLocale(['invalid'], allLocales)).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns the first matching locale', () => {
|
|
|
|
|
expect(getClosestAvailableLocale(['invalid', 'ar', 'bg'], allLocales)).toBe('ar');
|
|
|
|
|
expect(getClosestAvailableLocale(['bg'], allLocales)).toBe('bg');
|
|
|
|
|
expect(getClosestAvailableLocale(['bg', 'invalid', 'ar'], allLocales)).toBe('bg');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns the locale for a less specific match', () => {
|
|
|
|
|
expect(getClosestAvailableLocale(['ar-AE'], allLocales)).toBe('ar-AE');
|
|
|
|
|
expect(getClosestAvailableLocale(['ar-AE', 'en'], allLocales)).toBe('ar-AE');
|
|
|
|
|
expect(getClosestAvailableLocale(['zh-Hans-HK', 'zh-Hans'], allLocales)).toBe('zh-Hans-HK');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignores the locale for a more specific match', () => {
|
|
|
|
|
expect(getClosestAvailableLocale(['zh'], allLocales)).toBeUndefined();
|
|
|
|
|
expect(getClosestAvailableLocale(['de', 'zh', 'en-US'], allLocales)).toBe('en-US');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|