]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/core-utils/i18n/i18n.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / core-utils / 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 'ar': 'العربية',
8 'ca-ES': 'Català',
9 'cs-CZ': 'Čeština',
10 'de-DE': 'Deutsch',
11 'el-GR': 'ελληνικά',
12 'eo': 'Esperanto',
13 'es-ES': 'Español',
14 'eu-ES': 'Euskara',
15 'fi-FI': 'suomi',
16 'fr-FR': 'Français',
17 'gd': 'Gàidhlig',
18 'gl-ES': 'galego',
19 'hu-HU': 'magyar',
20 'it-IT': 'Italiano',
21 'ja-JP': '日本語',
22 'kab': 'Taqbaylit',
23 'nl-NL': 'Nederlands',
24 'oc': 'Occitan',
25 'pl-PL': 'Polski',
26 'pt-BR': 'Português (Brasil)',
27 'pt-PT': 'Português (Portugal)',
28 'ru-RU': 'русский',
29 'sq': 'Shqip',
30 'sv-SE': 'Svenska',
31 'th-TH': 'ไทย',
32 'vi-VN': 'Tiếng Việt',
33 'zh-Hans-CN': '简体中文(中国)',
34 'zh-Hant-TW': '繁體中文(台灣)'
35 }
36
37 const I18N_LOCALE_ALIAS = {
38 'ar-001': 'ar',
39 'ca': 'ca-ES',
40 'cs': 'cs-CZ',
41 'de': 'de-DE',
42 'el': 'el-GR',
43 'en': 'en-US',
44 'es': 'es-ES',
45 'eu': 'eu-ES',
46 'fi': 'fi-FI',
47 'gl': 'gl-ES',
48 'fr': 'fr-FR',
49 'hu': 'hu-HU',
50 'it': 'it-IT',
51 'ja': 'ja-JP',
52 'nl': 'nl-NL',
53 'pl': 'pl-PL',
54 'pt': 'pt-BR',
55 'ru': 'ru-RU',
56 'sv': 'sv-SE',
57 'th': 'th-TH',
58 'vi': 'vi-VN',
59 'zh-CN': 'zh-Hans-CN',
60 'zh-Hans': 'zh-Hans-CN',
61 'zh-Hant': 'zh-Hant-TW',
62 'zh-TW': 'zh-Hant-TW',
63 'zh': 'zh-Hans-CN'
64 }
65
66 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
67 .concat(Object.keys(I18N_LOCALE_ALIAS))
68
69 export function getDefaultLocale () {
70 return 'en-US'
71 }
72
73 export function isDefaultLocale (locale: string) {
74 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
75 }
76
77 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
78 if (!translations || !translations[str]) return str
79
80 return translations[str]
81 }
82
83 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
84 export function is18nPath (path: string) {
85 return possiblePaths.includes(path)
86 }
87
88 export function is18nLocale (locale: string) {
89 return POSSIBLE_LOCALES.includes(locale)
90 }
91
92 export function getCompleteLocale (locale: string) {
93 if (!locale) return locale
94
95 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
96
97 return locale
98 }
99
100 export function getShortLocale (locale: string) {
101 if (locale.includes('-') === false) return locale
102
103 return locale.split('-')[0]
104 }
105
106 export function buildFileLocale (locale: string) {
107 return getCompleteLocale(locale)
108 }