]>
Commit | Line | Data |
---|---|---|
74b7c6d4 C |
1 | export const LOCALE_FILES = [ 'player', 'server' ] |
2 | ||
989e526a | 3 | export const I18N_LOCALES = { |
8afc19a6 | 4 | 'en-US': 'English', |
10e63b68 | 5 | 'fr-FR': 'Français', |
7f768064 Q |
6 | 'eu-ES': 'Euskara', |
7 | 'ca-ES': 'Català', | |
8 | 'cs-CZ': 'Čeština', | |
fb9e6cb0 C |
9 | 'eo': 'Esperanto', |
10 | 'de-DE': 'Deutsch', | |
7f768064 Q |
11 | 'es-ES': 'Español', |
12 | 'oc': 'Occitan', | |
a9155ee6 C |
13 | 'zh-Hant-TW': '中文 (繁體, 台灣)', |
14 | 'pt-BR': 'Português (Brasil)', | |
15 | 'sv-SE': 'svenska' | |
7f768064 | 16 | // 'pl-PL': 'Polski' |
989e526a C |
17 | } |
18 | ||
74b7c6d4 | 19 | const I18N_LOCALE_ALIAS = { |
9f164722 | 20 | 'en': 'en-US', |
10e63b68 C |
21 | 'fr': 'fr-FR', |
22 | 'eu': 'eu-ES', | |
a55e5579 | 23 | 'ca': 'ca-ES', |
fb9e6cb0 C |
24 | 'cs': 'cs-CZ', |
25 | 'de': 'de-DE', | |
a9155ee6 C |
26 | 'es': 'es-ES', |
27 | 'pt': 'pt-BR', | |
28 | 'sv': 'sv-SE' | |
10e63b68 | 29 | // 'pl': 'pl-PL' |
74b7c6d4 C |
30 | } |
31 | ||
32 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
33 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
34 | ||
989e526a C |
35 | export function getDefaultLocale () { |
36 | return 'en-US' | |
37 | } | |
38 | ||
e945b184 | 39 | export function isDefaultLocale (locale: string) { |
74b7c6d4 | 40 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) |
e945b184 C |
41 | } |
42 | ||
3dfa8494 C |
43 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { |
44 | return translations && translations[str] ? translations[str] : str | |
45 | } | |
46 | ||
8afc19a6 | 47 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) |
989e526a C |
48 | export function is18nPath (path: string) { |
49 | return possiblePaths.indexOf(path) !== -1 | |
50 | } | |
51 | ||
989e526a | 52 | export function is18nLocale (locale: string) { |
74b7c6d4 C |
53 | return POSSIBLE_LOCALES.indexOf(locale) !== -1 |
54 | } | |
55 | ||
56 | export function getCompleteLocale (locale: string) { | |
57 | if (!locale) return locale | |
58 | ||
59 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
60 | ||
61 | return locale | |
989e526a C |
62 | } |
63 | ||
9f164722 C |
64 | export function getShortLocale (locale: string) { |
65 | if (locale.indexOf('-') === -1) return locale | |
66 | ||
67 | return locale.split('-')[0] | |
68 | } | |
69 | ||
989e526a | 70 | export function buildFileLocale (locale: string) { |
74b7c6d4 | 71 | const completeLocale = getCompleteLocale(locale) |
989e526a | 72 | |
fb9e6cb0 | 73 | return completeLocale.replace(/-/g, '_') |
989e526a | 74 | } |