]>
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 | 'ar': 'العربية', | |
8 | 'ca-ES': 'Català', | |
9 | 'cs-CZ': 'Čeština', | |
10 | 'de-DE': 'Deutsch', | |
11 | 'el-GR': 'ελληνικά', | |
12 | 'eo': 'Esperanto', | |
13 | 'es-ES': 'Español', | |
14 | 'eu-ES': 'Euskara', | |
15 | 'fi-FI': 'suomi', | |
16 | 'fr-FR': 'Français', | |
17 | 'gd': 'Gàidhlig', | |
18 | 'gl-ES': 'galego', | |
19 | 'hu-HU': 'magyar', | |
20 | 'it-IT': 'Italiano', | |
21 | 'ja-JP': '日本語', | |
22 | 'kab': 'Taqbaylit', | |
23 | 'nl-NL': 'Nederlands', | |
24 | 'oc': 'Occitan', | |
25 | 'pl-PL': 'Polski', | |
26 | 'pt-BR': 'Português (Brasil)', | |
27 | 'pt-PT': 'Português (Portugal)', | |
28 | 'ru-RU': 'русский', | |
29 | 'sv-SE': 'svenska', | |
30 | 'th-TH': 'ไทย', | |
31 | 'vi-VN': 'Tiếng Việt', | |
32 | 'zh-Hans-CN': '简体中文(中国)', | |
33 | 'zh-Hant-TW': '繁體中文(台灣)' | |
34 | } | |
35 | ||
36 | const I18N_LOCALE_ALIAS = { | |
37 | 'ar-001': 'ar', | |
38 | 'ca': 'ca-ES', | |
39 | 'cs': 'cs-CZ', | |
40 | 'de': 'de-DE', | |
41 | 'el': 'el-GR', | |
42 | 'en': 'en-US', | |
43 | 'es': 'es-ES', | |
44 | 'eu': 'eu-ES', | |
45 | 'fi': 'fi-FI', | |
46 | 'gl': 'gl-ES', | |
47 | 'fr': 'fr-FR', | |
48 | 'hu': 'hu-HU', | |
49 | 'it': 'it-IT', | |
50 | 'ja': 'ja-JP', | |
51 | 'nl': 'nl-NL', | |
52 | 'pl': 'pl-PL', | |
53 | 'pt': 'pt-BR', | |
54 | 'ru': 'ru-RU', | |
55 | 'sv': 'sv-SE', | |
56 | 'th': 'th-TH', | |
57 | 'vi': 'vi-VN', | |
58 | 'zh-CN': 'zh-Hans-CN', | |
59 | 'zh-Hans': 'zh-Hans-CN', | |
60 | 'zh-Hant': 'zh-Hant-TW', | |
61 | 'zh-TW': 'zh-Hant-TW', | |
62 | 'zh': 'zh-Hans-CN' | |
63 | } | |
64 | ||
65 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
66 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
67 | ||
68 | export function getDefaultLocale () { | |
69 | return 'en-US' | |
70 | } | |
71 | ||
72 | export function isDefaultLocale (locale: string) { | |
73 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | |
74 | } | |
75 | ||
76 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | |
77 | // FIXME: remove disable rule when the client is upgraded to typescript 3.7 | |
78 | // eslint-disable-next-line | |
79 | return translations && translations[str] ? translations[str] : str | |
80 | } | |
81 | ||
82 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
83 | export function is18nPath (path: string) { | |
84 | return possiblePaths.includes(path) | |
85 | } | |
86 | ||
87 | export function is18nLocale (locale: string) { | |
88 | return POSSIBLE_LOCALES.includes(locale) | |
89 | } | |
90 | ||
91 | export function getCompleteLocale (locale: string) { | |
92 | if (!locale) return locale | |
93 | ||
94 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
95 | ||
96 | return locale | |
97 | } | |
98 | ||
99 | export function getShortLocale (locale: string) { | |
100 | if (locale.includes('-') === false) return locale | |
101 | ||
102 | return locale.split('-')[0] | |
103 | } | |
104 | ||
105 | export function buildFileLocale (locale: string) { | |
106 | return getCompleteLocale(locale) | |
107 | } |