]>
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 | 'el-GR': 'ελληνικά', | |
12 | 'de-DE': 'Deutsch', | |
13 | 'it-IT': 'Italiano', | |
14 | 'nl-NL': 'Nederlands', | |
15 | 'es-ES': 'Español', | |
16 | 'oc': 'Occitan', | |
17 | 'gd': 'Gàidhlig', | |
18 | 'zh-Hant-TW': '繁體中文(台灣)', | |
19 | 'pt-BR': 'Português (Brasil)', | |
20 | 'pt-PT': 'Português (Portugal)', | |
21 | 'sv-SE': 'svenska', | |
22 | 'pl-PL': 'Polski', | |
23 | 'fi-FI': 'suomi', | |
24 | 'ru-RU': 'русский', | |
25 | 'zh-Hans-CN': '简体中文(中国)' | |
26 | } | |
27 | ||
28 | const I18N_LOCALE_ALIAS = { | |
29 | 'en': 'en-US', | |
30 | 'fr': 'fr-FR', | |
31 | 'eu': 'eu-ES', | |
32 | 'ca': 'ca-ES', | |
33 | 'cs': 'cs-CZ', | |
34 | 'de': 'de-DE', | |
35 | 'es': 'es-ES', | |
36 | 'pt': 'pt-PT', | |
37 | 'fi': 'fi-FI', | |
38 | 'sv': 'sv-SE', | |
39 | 'pl': 'pl-PL', | |
40 | 'ru': 'ru-RU', | |
41 | 'nl': 'nl-NL', | |
42 | 'zh': 'zh-Hans-CN' | |
43 | } | |
44 | ||
45 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
46 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
47 | ||
48 | export function getDefaultLocale () { | |
49 | return 'en-US' | |
50 | } | |
51 | ||
52 | export function isDefaultLocale (locale: string) { | |
53 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | |
54 | } | |
55 | ||
56 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | |
57 | return translations && translations[str] ? translations[str] : str | |
58 | } | |
59 | ||
60 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
61 | export function is18nPath (path: string) { | |
62 | return possiblePaths.indexOf(path) !== -1 | |
63 | } | |
64 | ||
65 | export function is18nLocale (locale: string) { | |
66 | return POSSIBLE_LOCALES.indexOf(locale) !== -1 | |
67 | } | |
68 | ||
69 | export function getCompleteLocale (locale: string) { | |
70 | if (!locale) return locale | |
71 | ||
72 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
73 | ||
74 | return locale | |
75 | } | |
76 | ||
77 | export function getShortLocale (locale: string) { | |
78 | if (locale.indexOf('-') === -1) return locale | |
79 | ||
80 | return locale.split('-')[0] | |
81 | } | |
82 | ||
83 | export function buildFileLocale (locale: string) { | |
84 | const completeLocale = getCompleteLocale(locale) | |
85 | ||
86 | return completeLocale.replace(/-/g, '_') | |
87 | } |