Files
TREK/shared/src/i18n/languages.ts
T
Maurice 8f02337d45 fix(i18n): hand Intl and the document the real language tag for br and gr
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.
2026-10-07 16:34:59 +02:00

60 lines
2.6 KiB
TypeScript

export const SUPPORTED_LANGUAGES = [
{ value: 'de', label: 'Deutsch', locale: 'de-DE' },
{ value: 'en', label: 'English', locale: 'en-US' },
{ value: 'es', label: 'Español', locale: 'es-ES' },
{ value: 'et', label: 'Eesti', locale: 'et-EE' },
{ value: 'fr', label: 'Français', locale: 'fr-FR' },
{ value: 'hu', label: 'Magyar', locale: 'hu-HU' },
{ value: 'nl', label: 'Nederlands', locale: 'nl-NL' },
{ value: 'br', label: 'Português (Brasil)', locale: 'pt-BR' },
{ value: 'cs', label: 'Česky', locale: 'cs-CZ' },
{ value: 'sk', label: 'Slovenčina', locale: 'sk-SK' },
{ value: 'pl', label: 'Polski', locale: 'pl-PL' },
{ value: 'ru', label: 'Русский', locale: 'ru-RU' },
{ value: 'zh', label: '简体中文', locale: 'zh-CN' },
{ value: 'zh-TW', label: '繁體中文', locale: 'zh-TW' },
{ value: 'it', label: 'Italiano', locale: 'it-IT' },
{ value: 'tr', label: 'Türkçe', locale: 'tr-TR' },
{ value: 'ar', label: 'العربية', locale: 'ar-SA' },
{ value: 'az', label: 'Azərbaycanca', locale: 'az-AZ' },
{ value: 'id', label: 'Bahasa Indonesia', locale: 'id-ID' },
{ value: 'ja', label: '日本語', locale: 'ja-JP' },
{ value: 'ko', label: '한국어', locale: 'ko-KR' },
{ value: 'th', label: 'ไทย', locale: 'th-TH' },
{ value: 'uk', label: 'Українська', locale: 'uk-UA' },
{ value: 'gr', label: 'Ελληνικά', locale: 'el-GR' },
{ value: 'sv', label: 'Svenska', locale: 'sv-SE' },
{ value: 'vi', label: 'Tiếng Việt', locale: 'vi-VN' },
{ value: 'ca', label: 'Català', locale: 'ca-ES' },
] as const;
export type SupportedLanguageCode = (typeof SUPPORTED_LANGUAGES)[number]['value'];
export const SUPPORTED_LANGUAGE_CODES: string[] = SUPPORTED_LANGUAGES.map((l) => l.value);
const LOCALES: Partial<Record<string, string>> = Object.fromEntries(
SUPPORTED_LANGUAGES.map((l) => [l.value, l.locale]),
);
// Languages displayed right-to-left.
const RTL_LANGUAGES = new Set<string>(['ar']);
export function getLocaleForLanguage(language: string): string {
return LOCALES[language] ?? LOCALES['en'] ?? 'en-US';
}
// Two codes TREK uses are not the BCP-47 tag of their language: 'br' is Breton
// and 'gr' is no language at all.
const INTL_LANGUAGE: Partial<Record<string, string>> = { br: 'pt-BR', gr: 'el' };
// Returns a BCP-47 tag suitable for Intl APIs and the document's lang attribute.
export function getIntlLanguage(language: string): string {
const tag = INTL_LANGUAGE[language];
if (tag) return tag;
return SUPPORTED_LANGUAGE_CODES.includes(language) ? language : 'en';
}
export function isRtlLanguage(language: string): boolean {
return RTL_LANGUAGES.has(language);
}