]>
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 | 'zh-CN': 'zh-Hans-CN', | |
44 | 'zh-TW': 'zh-Hant-TW' | |
45 | } | |
46 | ||
47 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
48 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
49 | ||
50 | export function getDefaultLocale () { | |
51 | return 'en-US' | |
52 | } | |
53 | ||
54 | export function isDefaultLocale (locale: string) { | |
55 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | |
56 | } | |
57 | ||
58 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | |
59 | return translations && translations[str] ? translations[str] : str | |
60 | } | |
61 | ||
62 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
63 | export function is18nPath (path: string) { | |
64 | return possiblePaths.indexOf(path) !== -1 | |
65 | } | |
66 | ||
67 | export function is18nLocale (locale: string) { | |
68 | return POSSIBLE_LOCALES.indexOf(locale) !== -1 | |
69 | } | |
70 | ||
71 | export function getCompleteLocale (locale: string) { | |
72 | if (!locale) return locale | |
73 | ||
74 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
75 | ||
76 | return locale | |
77 | } | |
78 | ||
79 | export function getShortLocale (locale: string) { | |
80 | if (locale.indexOf('-') === -1) return locale | |
81 | ||
82 | return locale.split('-')[0] | |
83 | } | |
84 | ||
85 | export function buildFileLocale (locale: string) { | |
86 | const completeLocale = getCompleteLocale(locale) | |
87 | ||
88 | return completeLocale.replace(/-/g, '_') | |
89 | } |