| Total Complexity | 7 |
| Complexity/F | 1.17 |
| Lines of Code | 60 |
| Function Count | 6 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | export type WordlistLanguage = |
||
| 2 | | 'english' |
||
| 3 | | 'spanish' |
||
| 4 | | 'french' |
||
| 5 | | 'czech' |
||
| 6 | | 'italian' |
||
| 7 | | 'portuguese' |
||
| 8 | | 'japanese' |
||
| 9 | | 'korean' |
||
| 10 | | 'chinese_simplified' |
||
| 11 | | 'chinese_traditional'; |
||
| 12 | |||
| 13 | export type UILanguage = 'en' | 'es' | 'fr' | 'cs' | 'it' | 'pt' | 'ja' | 'ko' | 'zh-Hans' | 'zh-Hant'; |
||
| 14 | |||
| 15 | export const DEFAULT_LANGUAGE: WordlistLanguage = 'english'; |
||
| 16 | export const DEFAULT_UI_LANGUAGE: UILanguage = 'en'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Mapping from wordlist language to UI language code |
||
| 20 | */ |
||
| 21 | const wordlistToUIMap: Record<WordlistLanguage, UILanguage> = { |
||
| 22 | english: 'en', |
||
| 23 | spanish: 'es', |
||
| 24 | french: 'fr', |
||
| 25 | czech: 'cs', |
||
| 26 | italian: 'it', |
||
| 27 | portuguese: 'pt', |
||
| 28 | japanese: 'ja', |
||
| 29 | korean: 'ko', |
||
| 30 | chinese_simplified: 'zh-Hans', |
||
| 31 | chinese_traditional: 'zh-Hant', |
||
| 32 | }; |
||
| 33 | |||
| 34 | export function wordlistToUILanguage(wordlistLang: string): UILanguage { |
||
| 35 | return wordlistToUIMap[wordlistLang as WordlistLanguage] || DEFAULT_UI_LANGUAGE; |
||
| 36 | } |
||
| 37 | |||
| 38 | export function getDefaultLanguage(): WordlistLanguage { |
||
| 39 | return DEFAULT_LANGUAGE; |
||
| 40 | } |
||
| 41 | |||
| 42 | export function determineLanguage(savedLanguage: string | null): WordlistLanguage { |
||
| 43 | if (savedLanguage && isValidWordlistLanguage(savedLanguage)) { |
||
| 44 | return savedLanguage as WordlistLanguage; |
||
| 45 | } |
||
| 46 | return DEFAULT_LANGUAGE; |
||
| 47 | } |
||
| 48 | |||
| 49 | export function isValidWordlistLanguage(lang: string): boolean { |
||
| 50 | return Object.keys(wordlistToUIMap).includes(lang); |
||
| 51 | } |
||
| 52 | |||
| 53 | export function languagesMatch(lang1: string, lang2: string): boolean { |
||
| 54 | return lang1 === lang2; |
||
| 55 | } |
||
| 56 | |||
| 57 | export function getSupportedLanguages(): WordlistLanguage[] { |
||
| 58 | return Object.keys(wordlistToUIMap) as WordlistLanguage[]; |
||
| 59 | } |
||
| 60 |