]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/i18n/i18n.ts
Stop using tsconfig register
[github/Chocobozzz/PeerTube.git] / shared / core-utils / i18n / i18n.ts
CommitLineData
74b7c6d4
C
1export const LOCALE_FILES = [ 'player', 'server' ]
2
c199c427 3export const I18N_LOCALES = {
bfa3a5d0
C
4 // Always first to avoid issues when using express acceptLanguages function when no accept language header is set
5 'en-US': 'English',
6
d10538b4 7 'ar': 'العربية',
7f768064
Q
8 'ca-ES': 'Català',
9 'cs-CZ': 'Čeština',
fb9e6cb0 10 'de-DE': 'Deutsch',
0df21c79 11 'el-GR': 'ελληνικά',
0df21c79
C
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',
c7444546 18 'gl-ES': 'galego',
0df21c79 19 'hu-HU': 'magyar',
d7aea77b 20 'it-IT': 'Italiano',
0df21c79 21 'ja-JP': '日本語',
0bd558a0 22 'kab': 'Taqbaylit',
8137c8b9 23 'nl-NL': 'Nederlands',
2a39506c 24 'oc': 'Occitan',
0df21c79 25 'pl-PL': 'Polski',
a9155ee6 26 'pt-BR': 'Português (Brasil)',
8137c8b9 27 'pt-PT': 'Português (Portugal)',
d7aea77b 28 'ru-RU': 'русский',
f45aa01a
C
29 'sq': 'Shqip',
30 'sv-SE': 'Svenska',
66175ae8
C
31 'nn': 'norsk nynorsk',
32 'nb-NO': 'norsk bokmål',
0df21c79 33 'th-TH': 'ไทย',
0bd558a0 34 'vi-VN': 'Tiếng Việt',
0df21c79
C
35 'zh-Hans-CN': '简体中文(中国)',
36 'zh-Hant-TW': '繁體中文(台灣)'
989e526a
C
37}
38
c199c427 39const I18N_LOCALE_ALIAS = {
d10538b4 40 'ar-001': 'ar',
a55e5579 41 'ca': 'ca-ES',
fb9e6cb0
C
42 'cs': 'cs-CZ',
43 'de': 'de-DE',
1fe654e0 44 'el': 'el-GR',
0df21c79 45 'en': 'en-US',
a9155ee6 46 'es': 'es-ES',
0df21c79 47 'eu': 'eu-ES',
82054691 48 'fi': 'fi-FI',
c7444546 49 'gl': 'gl-ES',
0df21c79
C
50 'fr': 'fr-FR',
51 'hu': 'hu-HU',
0bd558a0
C
52 'it': 'it-IT',
53 'ja': 'ja-JP',
0df21c79 54 'nl': 'nl-NL',
d7aea77b 55 'pl': 'pl-PL',
1fe654e0 56 'pt': 'pt-BR',
66175ae8 57 'nb': 'nb-NO',
8137c8b9 58 'ru': 'ru-RU',
0df21c79
C
59 'sv': 'sv-SE',
60 'th': 'th-TH',
0bd558a0 61 'vi': 'vi-VN',
f69ec5f3 62 'zh-CN': 'zh-Hans-CN',
0bd558a0 63 'zh-Hans': 'zh-Hans-CN',
1fe654e0 64 'zh-Hant': 'zh-Hant-TW',
0bd558a0
C
65 'zh-TW': 'zh-Hant-TW',
66 'zh': 'zh-Hans-CN'
74b7c6d4
C
67}
68
69export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
70 .concat(Object.keys(I18N_LOCALE_ALIAS))
71
989e526a
C
72export function getDefaultLocale () {
73 return 'en-US'
74}
75
e945b184 76export function isDefaultLocale (locale: string) {
74b7c6d4 77 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
e945b184
C
78}
79
3dfa8494 80export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
67baf647
C
81 if (!translations || !translations[str]) return str
82
83 return translations[str]
3dfa8494
C
84}
85
8afc19a6 86const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
989e526a 87export function is18nPath (path: string) {
bdd428a6 88 return possiblePaths.includes(path)
989e526a
C
89}
90
989e526a 91export function is18nLocale (locale: string) {
bdd428a6 92 return POSSIBLE_LOCALES.includes(locale)
74b7c6d4
C
93}
94
95export function getCompleteLocale (locale: string) {
96 if (!locale) return locale
97
98 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
99
100 return locale
989e526a
C
101}
102
9f164722 103export function getShortLocale (locale: string) {
bdd428a6 104 if (locale.includes('-') === false) return locale
9f164722
C
105
106 return locale.split('-')[0]
107}
108
989e526a 109export function buildFileLocale (locale: string) {
350131cb 110 return getCompleteLocale(locale)
989e526a 111}