]>
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', | |
fb1b0ed9 | 17 | 'gd': 'Gàidhlig', |
1e45c78f | 18 | 'zh-Hant-TW': '繁體中文(台灣)', |
a9155ee6 | 19 | 'pt-BR': 'Português (Brasil)', |
8137c8b9 | 20 | 'pt-PT': 'Português (Portugal)', |
1e45c78f | 21 | 'sv-SE': 'svenska', |
d7aea77b | 22 | 'pl-PL': 'Polski', |
82054691 | 23 | 'fi-FI': 'suomi', |
d7aea77b | 24 | 'ru-RU': 'русский', |
1e45c78f | 25 | 'zh-Hans-CN': '简体中文(中国)' |
989e526a C |
26 | } |
27 | ||
c199c427 | 28 | const I18N_LOCALE_ALIAS = { |
9f164722 | 29 | 'en': 'en-US', |
10e63b68 C |
30 | 'fr': 'fr-FR', |
31 | 'eu': 'eu-ES', | |
a55e5579 | 32 | 'ca': 'ca-ES', |
fb9e6cb0 C |
33 | 'cs': 'cs-CZ', |
34 | 'de': 'de-DE', | |
a9155ee6 | 35 | 'es': 'es-ES', |
8137c8b9 | 36 | 'pt': 'pt-PT', |
82054691 | 37 | 'fi': 'fi-FI', |
d7aea77b C |
38 | 'sv': 'sv-SE', |
39 | 'pl': 'pl-PL', | |
8137c8b9 C |
40 | 'ru': 'ru-RU', |
41 | 'nl': 'nl-NL', | |
42 | 'zh': 'zh-Hans-CN' | |
74b7c6d4 C |
43 | } |
44 | ||
45 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
46 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
47 | ||
989e526a C |
48 | export function getDefaultLocale () { |
49 | return 'en-US' | |
50 | } | |
51 | ||
e945b184 | 52 | export function isDefaultLocale (locale: string) { |
74b7c6d4 | 53 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) |
e945b184 C |
54 | } |
55 | ||
3dfa8494 C |
56 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { |
57 | return translations && translations[str] ? translations[str] : str | |
58 | } | |
59 | ||
8afc19a6 | 60 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) |
989e526a C |
61 | export function is18nPath (path: string) { |
62 | return possiblePaths.indexOf(path) !== -1 | |
63 | } | |
64 | ||
989e526a | 65 | export function is18nLocale (locale: string) { |
74b7c6d4 C |
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 | |
989e526a C |
75 | } |
76 | ||
9f164722 C |
77 | export function getShortLocale (locale: string) { |
78 | if (locale.indexOf('-') === -1) return locale | |
79 | ||
80 | return locale.split('-')[0] | |
81 | } | |
82 | ||
989e526a | 83 | export function buildFileLocale (locale: string) { |
74b7c6d4 | 84 | const completeLocale = getCompleteLocale(locale) |
989e526a | 85 | |
fb9e6cb0 | 86 | return completeLocale.replace(/-/g, '_') |
989e526a | 87 | } |