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