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