]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/i18n/i18n.ts
Merge branch 'master' 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 // 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 'pl-PL': 'Polski',
22 'pt-BR': 'Português (Brasil)',
23 'pt-PT': 'Português (Portugal)',
24 'ru-RU': 'русский',
25 'sv-SE': 'svenska',
26 'th-TH': 'ไทย',
27 'zh-Hans-CN': '简体中文(中国)',
28 'zh-Hant-TW': '繁體中文(台灣)'
29 }
30
31 const I18N_LOCALE_ALIAS = {
32 'ca': 'ca-ES',
33 'cs': 'cs-CZ',
34 'de': 'de-DE',
35 'el': 'el-GR',
36 'en': 'en-US',
37 'es': 'es-ES',
38 'eu': 'eu-ES',
39 'fi': 'fi-FI',
40 'fr': 'fr-FR',
41 'ja': 'ja-JP',
42 'it': 'it-IT',
43 'hu': 'hu-HU',
44 'nl': 'nl-NL',
45 'pl': 'pl-PL',
46 'pt': 'pt-BR',
47 'ru': 'ru-RU',
48 'sv': 'sv-SE',
49 'th': 'th-TH',
50 'zh': 'zh-Hans-CN',
51 'zh-Hans': 'zh-Hans-CN',
52 'zh-CN': 'zh-Hans-CN',
53 'zh-Hant': 'zh-Hant-TW',
54 'zh-TW': 'zh-Hant-TW'
55 }
56
57 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
58 .concat(Object.keys(I18N_LOCALE_ALIAS))
59
60 export function getDefaultLocale () {
61 return 'en-US'
62 }
63
64 export function isDefaultLocale (locale: string) {
65 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
66 }
67
68 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
69 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
70 // eslint-disable-next-line
71 return translations && translations[str] ? translations[str] : str
72 }
73
74 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
75 export function is18nPath (path: string) {
76 return possiblePaths.includes(path)
77 }
78
79 export function is18nLocale (locale: string) {
80 return POSSIBLE_LOCALES.includes(locale)
81 }
82
83 export function getCompleteLocale (locale: string) {
84 if (!locale) return locale
85
86 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
87
88 return locale
89 }
90
91 export function getShortLocale (locale: string) {
92 if (locale.includes('-') === false) return locale
93
94 return locale.split('-')[0]
95 }
96
97 export function buildFileLocale (locale: string) {
98 return getCompleteLocale(locale)
99 }