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