Revert "Remove oc locale support"
[oweals/peertube.git] / shared / models / i18n / i18n.ts
1 export const LOCALE_FILES = [ 'player', 'server' ]
2
3 export const I18N_LOCALES = {
4   // Always first to avoid issues when using express acceptLanguages function when no accept language header is set
5   'en-US': 'English',
6
7   'ca-ES': 'Català',
8   'cs-CZ': 'Čeština',
9   'de-DE': 'Deutsch',
10   'el-GR': 'ελληνικά',
11   'eo': 'Esperanto',
12   'es-ES': 'Español',
13   'eu-ES': 'Euskara',
14   'fi-FI': 'suomi',
15   'fr-FR': 'Français',
16   'gd': 'Gàidhlig',
17   'hu-HU': 'magyar',
18   'it-IT': 'Italiano',
19   'ja-JP': '日本語',
20   'nl-NL': 'Nederlands',
21   'oc': 'Occitan',
22   'pl-PL': 'Polski',
23   'pt-BR': 'Português (Brasil)',
24   'pt-PT': 'Português (Portugal)',
25   'ru-RU': 'русский',
26   'sv-SE': 'svenska',
27   'th-TH': 'ไทย',
28   'zh-Hans-CN': '简体中文(中国)',
29   'zh-Hant-TW': '繁體中文(台灣)'
30 }
31
32 const I18N_LOCALE_ALIAS = {
33   'ca': 'ca-ES',
34   'cs': 'cs-CZ',
35   'de': 'de-DE',
36   'el': 'el-GR',
37   'en': 'en-US',
38   'es': 'es-ES',
39   'eu': 'eu-ES',
40   'fi': 'fi-FI',
41   'fr': 'fr-FR',
42   'ja': 'ja-JP',
43   'it': 'it-IT',
44   'hu': 'hu-HU',
45   'nl': 'nl-NL',
46   'pl': 'pl-PL',
47   'pt': 'pt-BR',
48   'ru': 'ru-RU',
49   'sv': 'sv-SE',
50   'th': 'th-TH',
51   'zh': 'zh-Hans-CN',
52   'zh-Hans': 'zh-Hans-CN',
53   'zh-CN': 'zh-Hans-CN',
54   'zh-Hant': 'zh-Hant-TW',
55   'zh-TW': 'zh-Hant-TW'
56 }
57
58 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
59                                       .concat(Object.keys(I18N_LOCALE_ALIAS))
60
61 export function getDefaultLocale () {
62   return 'en-US'
63 }
64
65 export function isDefaultLocale (locale: string) {
66   return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
67 }
68
69 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
70   // FIXME: remove disable rule when the client is upgraded to typescript 3.7
71   // eslint-disable-next-line
72   return translations && translations[str] ? translations[str] : str
73 }
74
75 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
76 export function is18nPath (path: string) {
77   return possiblePaths.includes(path)
78 }
79
80 export function is18nLocale (locale: string) {
81   return POSSIBLE_LOCALES.includes(locale)
82 }
83
84 export function getCompleteLocale (locale: string) {
85   if (!locale) return locale
86
87   if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
88
89   return locale
90 }
91
92 export function getShortLocale (locale: string) {
93   if (locale.includes('-') === false) return locale
94
95   return locale.split('-')[0]
96 }
97
98 export function buildFileLocale (locale: string) {
99   return getCompleteLocale(locale)
100 }