]>
Commit | Line | Data |
---|---|---|
1 | export const LOCALE_FILES = [ 'player', 'server' ] | |
2 | ||
3 | export const I18N_LOCALES = { | |
4 | // Always first to avoid issues when using express acceptLanguages function when no accept language header is set | |
5 | 'en-US': 'English', | |
6 | ||
7 | // Keep it alphabetically sorted | |
8 | 'ar': 'العربية', | |
9 | 'ca-ES': 'Català', | |
10 | 'cs-CZ': 'Čeština', | |
11 | 'de-DE': 'Deutsch', | |
12 | 'el-GR': 'ελληνικά', | |
13 | 'eo': 'Esperanto', | |
14 | 'es-ES': 'Español', | |
15 | 'eu-ES': 'Euskara', | |
16 | 'fa-IR': 'فارسی', | |
17 | 'fi-FI': 'Suomi', | |
18 | 'fr-FR': 'Français', | |
19 | 'gd': 'Gàidhlig', | |
20 | 'gl-ES': 'Galego', | |
21 | 'hr': 'Hrvatski', | |
22 | 'hu-HU': 'Magyar', | |
23 | 'is': 'Íslenska', | |
24 | 'it-IT': 'Italiano', | |
25 | 'ja-JP': '日本語', | |
26 | 'kab': 'Taqbaylit', | |
27 | 'nb-NO': 'Norsk bokmål', | |
28 | 'nl-NL': 'Nederlands', | |
29 | 'nn': 'Norsk nynorsk', | |
30 | 'oc': 'Occitan', | |
31 | 'pl-PL': 'Polski', | |
32 | 'pt-BR': 'Português (Brasil)', | |
33 | 'pt-PT': 'Português (Portugal)', | |
34 | 'ru-RU': 'Pусский', | |
35 | 'sq': 'Shqip', | |
36 | 'sv-SE': 'Svenska', | |
37 | 'th-TH': 'ไทย', | |
38 | 'tok': 'Toki Pona', | |
39 | 'uk-UA': 'украї́нська мо́ва', | |
40 | 'vi-VN': 'Tiếng Việt', | |
41 | 'zh-Hans-CN': '简体中文(中国)', | |
42 | 'zh-Hant-TW': '繁體中文(台灣)' | |
43 | } | |
44 | ||
45 | // Keep it alphabetically sorted | |
46 | const I18N_LOCALE_ALIAS = { | |
47 | 'ar-001': 'ar', | |
48 | 'ca': 'ca-ES', | |
49 | 'cs': 'cs-CZ', | |
50 | 'de': 'de-DE', | |
51 | 'el': 'el-GR', | |
52 | 'en': 'en-US', | |
53 | 'es': 'es-ES', | |
54 | 'eu': 'eu-ES', | |
55 | 'fa': 'fa-IR', | |
56 | 'fi': 'fi-FI', | |
57 | 'fr': 'fr-FR', | |
58 | 'gl': 'gl-ES', | |
59 | 'hu': 'hu-HU', | |
60 | 'it': 'it-IT', | |
61 | 'ja': 'ja-JP', | |
62 | 'nb': 'nb-NO', | |
63 | 'nl': 'nl-NL', | |
64 | 'pl': 'pl-PL', | |
65 | 'pt': 'pt-BR', | |
66 | 'ru': 'ru-RU', | |
67 | 'sv': 'sv-SE', | |
68 | 'th': 'th-TH', | |
69 | 'uk': 'uk-UA', | |
70 | 'vi': 'vi-VN', | |
71 | 'zh-CN': 'zh-Hans-CN', | |
72 | 'zh-Hans': 'zh-Hans-CN', | |
73 | 'zh-Hant': 'zh-Hant-TW', | |
74 | 'zh-TW': 'zh-Hant-TW', | |
75 | 'zh': 'zh-Hans-CN' | |
76 | } | |
77 | ||
78 | export const POSSIBLE_LOCALES = (Object.keys(I18N_LOCALES) as string[]).concat(Object.keys(I18N_LOCALE_ALIAS)) | |
79 | ||
80 | export function getDefaultLocale () { | |
81 | return 'en-US' | |
82 | } | |
83 | ||
84 | export function isDefaultLocale (locale: string) { | |
85 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | |
86 | } | |
87 | ||
88 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | |
89 | if (!translations?.[str]) return str | |
90 | ||
91 | return translations[str] | |
92 | } | |
93 | ||
94 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
95 | export function is18nPath (path: string) { | |
96 | return possiblePaths.includes(path) | |
97 | } | |
98 | ||
99 | export function is18nLocale (locale: string) { | |
100 | return POSSIBLE_LOCALES.includes(locale) | |
101 | } | |
102 | ||
103 | export function getCompleteLocale (locale: string) { | |
104 | if (!locale) return locale | |
105 | ||
106 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
107 | ||
108 | return locale | |
109 | } | |
110 | ||
111 | export function getShortLocale (locale: string) { | |
112 | if (locale.includes('-') === false) return locale | |
113 | ||
114 | return locale.split('-')[0] | |
115 | } | |
116 | ||
117 | export function buildFileLocale (locale: string) { | |
118 | return getCompleteLocale(locale) | |
119 | } |