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> = Object.fromEntries( SUPPORTED_LANGUAGES.map((l) => [l.value, l.locale]), ); // Languages displayed right-to-left. const RTL_LANGUAGES = new Set(['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> = { 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); }