mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
8f02337d45
TREK's codes 'br' (Brazilian Portuguese) and 'gr' (Greek) went straight into <html lang> and into ten Intl calls. 'br' is Breton, so Brazilian users got Breton month names and screen readers announced the page as Breton; 'gr' is no language at all, so Greek users got the default locale. getIntlLanguage maps both, and every one of those sites goes through it.
24 lines
866 B
TypeScript
24 lines
866 B
TypeScript
import { getIntlLanguage, SUPPORTED_LANGUAGES } from './languages';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
describe('getIntlLanguage', () => {
|
|
it('maps the two codes that are not the BCP-47 tag of their language', () => {
|
|
expect(getIntlLanguage('br')).toBe('pt-BR');
|
|
expect(getIntlLanguage('gr')).toBe('el');
|
|
});
|
|
|
|
it('passes every other supported code through and falls back to English', () => {
|
|
expect(getIntlLanguage('de')).toBe('de');
|
|
expect(getIntlLanguage('zh-TW')).toBe('zh-TW');
|
|
expect(getIntlLanguage('xx')).toBe('en');
|
|
});
|
|
|
|
it('gives Intl a tag it formats in the right language for every supported code', () => {
|
|
for (const { value, locale } of SUPPORTED_LANGUAGES) {
|
|
const primary = locale.split('-')[0];
|
|
expect(new Intl.Locale(getIntlLanguage(value)).language, value).toBe(primary);
|
|
}
|
|
});
|
|
});
|