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