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