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