]>
Commit | Line | Data |
---|---|---|
74b7c6d4 C |
1 | export const LOCALE_FILES = [ 'player', 'server' ] |
2 | ||
c199c427 | 3 | export const I18N_LOCALES = { |
bfa3a5d0 C |
4 | // Always first to avoid issues when using express acceptLanguages function when no accept language header is set |
5 | 'en-US': 'English', | |
6 | ||
d10538b4 | 7 | 'ar': 'العربية', |
7f768064 Q |
8 | 'ca-ES': 'Català', |
9 | 'cs-CZ': 'Čeština', | |
fb9e6cb0 | 10 | 'de-DE': 'Deutsch', |
0df21c79 | 11 | 'el-GR': 'ελληνικά', |
0df21c79 C |
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', | |
c7444546 | 18 | 'gl-ES': 'galego', |
0df21c79 | 19 | 'hu-HU': 'magyar', |
d7aea77b | 20 | 'it-IT': 'Italiano', |
0df21c79 | 21 | 'ja-JP': '日本語', |
0bd558a0 | 22 | 'kab': 'Taqbaylit', |
8137c8b9 | 23 | 'nl-NL': 'Nederlands', |
2a39506c | 24 | 'oc': 'Occitan', |
0df21c79 | 25 | 'pl-PL': 'Polski', |
a9155ee6 | 26 | 'pt-BR': 'Português (Brasil)', |
8137c8b9 | 27 | 'pt-PT': 'Português (Portugal)', |
d7aea77b | 28 | 'ru-RU': 'русский', |
0df21c79 C |
29 | 'sv-SE': 'svenska', |
30 | 'th-TH': 'ไทย', | |
0bd558a0 | 31 | 'vi-VN': 'Tiếng Việt', |
0df21c79 C |
32 | 'zh-Hans-CN': '简体中文(中国)', |
33 | 'zh-Hant-TW': '繁體中文(台灣)' | |
989e526a C |
34 | } |
35 | ||
c199c427 | 36 | const I18N_LOCALE_ALIAS = { |
d10538b4 | 37 | 'ar-001': 'ar', |
a55e5579 | 38 | 'ca': 'ca-ES', |
fb9e6cb0 C |
39 | 'cs': 'cs-CZ', |
40 | 'de': 'de-DE', | |
1fe654e0 | 41 | 'el': 'el-GR', |
0df21c79 | 42 | 'en': 'en-US', |
a9155ee6 | 43 | 'es': 'es-ES', |
0df21c79 | 44 | 'eu': 'eu-ES', |
82054691 | 45 | 'fi': 'fi-FI', |
c7444546 | 46 | 'gl': 'gl-ES', |
0df21c79 C |
47 | 'fr': 'fr-FR', |
48 | 'hu': 'hu-HU', | |
0bd558a0 C |
49 | 'it': 'it-IT', |
50 | 'ja': 'ja-JP', | |
0df21c79 | 51 | 'nl': 'nl-NL', |
d7aea77b | 52 | 'pl': 'pl-PL', |
1fe654e0 | 53 | 'pt': 'pt-BR', |
8137c8b9 | 54 | 'ru': 'ru-RU', |
0df21c79 C |
55 | 'sv': 'sv-SE', |
56 | 'th': 'th-TH', | |
0bd558a0 | 57 | 'vi': 'vi-VN', |
f69ec5f3 | 58 | 'zh-CN': 'zh-Hans-CN', |
0bd558a0 | 59 | 'zh-Hans': 'zh-Hans-CN', |
1fe654e0 | 60 | 'zh-Hant': 'zh-Hant-TW', |
0bd558a0 C |
61 | 'zh-TW': 'zh-Hant-TW', |
62 | 'zh': 'zh-Hans-CN' | |
74b7c6d4 C |
63 | } |
64 | ||
65 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
66 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
67 | ||
989e526a C |
68 | export function getDefaultLocale () { |
69 | return 'en-US' | |
70 | } | |
71 | ||
e945b184 | 72 | export function isDefaultLocale (locale: string) { |
74b7c6d4 | 73 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) |
e945b184 C |
74 | } |
75 | ||
3dfa8494 | 76 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { |
a1587156 C |
77 | // FIXME: remove disable rule when the client is upgraded to typescript 3.7 |
78 | // eslint-disable-next-line | |
3dfa8494 C |
79 | return translations && translations[str] ? translations[str] : str |
80 | } | |
81 | ||
8afc19a6 | 82 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) |
989e526a | 83 | export function is18nPath (path: string) { |
bdd428a6 | 84 | return possiblePaths.includes(path) |
989e526a C |
85 | } |
86 | ||
989e526a | 87 | export function is18nLocale (locale: string) { |
bdd428a6 | 88 | return POSSIBLE_LOCALES.includes(locale) |
74b7c6d4 C |
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 | |
989e526a C |
97 | } |
98 | ||
9f164722 | 99 | export function getShortLocale (locale: string) { |
bdd428a6 | 100 | if (locale.includes('-') === false) return locale |
9f164722 C |
101 | |
102 | return locale.split('-')[0] | |
103 | } | |
104 | ||
989e526a | 105 | export function buildFileLocale (locale: string) { |
350131cb | 106 | return getCompleteLocale(locale) |
989e526a | 107 | } |