]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/i18n/i18n.ts
Merge branch 'release/beta-10' into develop
[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 'zh-Hant-TW': '中文 (繁體, 台灣)'
13 // 'pl-PL': 'polski'
14 }
15
16 const I18N_LOCALE_ALIAS = {
17 'en': 'en-US',
18 'fr': 'fr-FR',
19 'eu': 'eu-ES',
20 'ca': 'ca-ES',
21 'cs': 'cs-CZ',
22 'de': 'de-DE',
23 'es': 'es-ES'
24 // 'pl': 'pl-PL'
25 }
26
27 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
28 .concat(Object.keys(I18N_LOCALE_ALIAS))
29
30 export function getDefaultLocale () {
31 return 'en-US'
32 }
33
34 export function isDefaultLocale (locale: string) {
35 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
36 }
37
38 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
39 export function is18nPath (path: string) {
40 return possiblePaths.indexOf(path) !== -1
41 }
42
43 export function is18nLocale (locale: string) {
44 return POSSIBLE_LOCALES.indexOf(locale) !== -1
45 }
46
47 export function getCompleteLocale (locale: string) {
48 if (!locale) return locale
49
50 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
51
52 return locale
53 }
54
55 export function getShortLocale (locale: string) {
56 if (locale.indexOf('-') === -1) return locale
57
58 return locale.split('-')[0]
59 }
60
61 export function buildFileLocale (locale: string) {
62 const completeLocale = getCompleteLocale(locale)
63
64 return completeLocale.replace(/-/g, '_')
65 }