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