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