Support occitan
[oweals/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   // 'pl-PL': 'polski'
15 }
16
17 const I18N_LOCALE_ALIAS = {
18   'en': 'en-US',
19   'fr': 'fr-FR',
20   'eu': 'eu-ES',
21   'ca': 'ca-ES',
22   'cs': 'cs-CZ',
23   'de': 'de-DE',
24   'es': 'es-ES'
25   // 'pl': 'pl-PL'
26 }
27
28 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
29                                       .concat(Object.keys(I18N_LOCALE_ALIAS))
30
31 export function getDefaultLocale () {
32   return 'en-US'
33 }
34
35 export function isDefaultLocale (locale: string) {
36   return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
37 }
38
39 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
40 export function is18nPath (path: string) {
41   return possiblePaths.indexOf(path) !== -1
42 }
43
44 export function is18nLocale (locale: string) {
45   return POSSIBLE_LOCALES.indexOf(locale) !== -1
46 }
47
48 export function getCompleteLocale (locale: string) {
49   if (!locale) return locale
50
51   if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
52
53   return locale
54 }
55
56 export function getShortLocale (locale: string) {
57   if (locale.indexOf('-') === -1) return locale
58
59   return locale.split('-')[0]
60 }
61
62 export function buildFileLocale (locale: string) {
63   const completeLocale = getCompleteLocale(locale)
64
65   return completeLocale.replace(/-/g, '_')
66 }