]>
Commit | Line | Data |
---|---|---|
1 | export const LOCALE_FILES = [ 'player', 'server' ] | |
2 | ||
3 | export const I18N_LOCALES = { | |
4 | 'en-US': 'English', | |
5 | 'fr-FR': 'Français', | |
6 | 'ja-JP': '日本語', | |
7 | 'eu-ES': 'Euskara', | |
8 | 'ca-ES': 'Català', | |
9 | 'cs-CZ': 'Čeština', | |
10 | 'eo': 'Esperanto', | |
11 | 'de-DE': 'Deutsch', | |
12 | 'it-IT': 'Italiano', | |
13 | 'nl-NL': 'Nederlands', | |
14 | 'es-ES': 'Español', | |
15 | 'oc': 'Occitan', | |
16 | 'zh-Hant-TW': '繁體中文(台灣)', | |
17 | 'pt-BR': 'Português (Brasil)', | |
18 | 'pt-PT': 'Português (Portugal)', | |
19 | 'sv-SE': 'svenska', | |
20 | 'pl-PL': 'Polski', | |
21 | 'ru-RU': 'русский', | |
22 | 'zh-Hans-CN': '简体中文(中国)' | |
23 | } | |
24 | ||
25 | const I18N_LOCALE_ALIAS = { | |
26 | 'en': 'en-US', | |
27 | 'fr': 'fr-FR', | |
28 | 'eu': 'eu-ES', | |
29 | 'ca': 'ca-ES', | |
30 | 'cs': 'cs-CZ', | |
31 | 'de': 'de-DE', | |
32 | 'es': 'es-ES', | |
33 | 'pt': 'pt-PT', | |
34 | 'sv': 'sv-SE', | |
35 | 'pl': 'pl-PL', | |
36 | 'ru': 'ru-RU', | |
37 | 'nl': 'nl-NL', | |
38 | 'zh': 'zh-Hans-CN' | |
39 | } | |
40 | ||
41 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
42 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
43 | ||
44 | export function getDefaultLocale () { | |
45 | return 'en-US' | |
46 | } | |
47 | ||
48 | export function isDefaultLocale (locale: string) { | |
49 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | |
50 | } | |
51 | ||
52 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | |
53 | return translations && translations[str] ? translations[str] : str | |
54 | } | |
55 | ||
56 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
57 | export function is18nPath (path: string) { | |
58 | return possiblePaths.indexOf(path) !== -1 | |
59 | } | |
60 | ||
61 | export function is18nLocale (locale: string) { | |
62 | return POSSIBLE_LOCALES.indexOf(locale) !== -1 | |
63 | } | |
64 | ||
65 | export function getCompleteLocale (locale: string) { | |
66 | if (!locale) return locale | |
67 | ||
68 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
69 | ||
70 | return locale | |
71 | } | |
72 | ||
73 | export function getShortLocale (locale: string) { | |
74 | if (locale.indexOf('-') === -1) return locale | |
75 | ||
76 | return locale.split('-')[0] | |
77 | } | |
78 | ||
79 | export function buildFileLocale (locale: string) { | |
80 | const completeLocale = getCompleteLocale(locale) | |
81 | ||
82 | return completeLocale.replace(/-/g, '_') | |
83 | } |