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