]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/i18n/i18n.ts
Translated using Weblate (Italian)
[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',
18 'hu-HU': 'magyar',
d7aea77b 19 'it-IT': 'Italiano',
0df21c79 20 'ja-JP': '日本語',
0bd558a0 21 'kab': 'Taqbaylit',
8137c8b9 22 'nl-NL': 'Nederlands',
2a39506c 23 'oc': 'Occitan',
0df21c79 24 'pl-PL': 'Polski',
a9155ee6 25 'pt-BR': 'Português (Brasil)',
8137c8b9 26 'pt-PT': 'Português (Portugal)',
d7aea77b 27 'ru-RU': 'русский',
0df21c79
C
28 'sv-SE': 'svenska',
29 'th-TH': 'ไทย',
0bd558a0 30 'vi-VN': 'Tiếng Việt',
0df21c79
C
31 'zh-Hans-CN': '简体中文(中国)',
32 'zh-Hant-TW': '繁體中文(台灣)'
989e526a
C
33}
34
c199c427 35const I18N_LOCALE_ALIAS = {
d10538b4 36 'ar-001': 'ar',
a55e5579 37 'ca': 'ca-ES',
fb9e6cb0
C
38 'cs': 'cs-CZ',
39 'de': 'de-DE',
1fe654e0 40 'el': 'el-GR',
0df21c79 41 'en': 'en-US',
a9155ee6 42 'es': 'es-ES',
0df21c79 43 'eu': 'eu-ES',
82054691 44 'fi': 'fi-FI',
0df21c79
C
45 'fr': 'fr-FR',
46 'hu': 'hu-HU',
0bd558a0
C
47 'it': 'it-IT',
48 'ja': 'ja-JP',
0df21c79 49 'nl': 'nl-NL',
d7aea77b 50 'pl': 'pl-PL',
1fe654e0 51 'pt': 'pt-BR',
8137c8b9 52 'ru': 'ru-RU',
0df21c79
C
53 'sv': 'sv-SE',
54 'th': 'th-TH',
0bd558a0 55 'vi': 'vi-VN',
f69ec5f3 56 'zh-CN': 'zh-Hans-CN',
0bd558a0 57 'zh-Hans': 'zh-Hans-CN',
1fe654e0 58 'zh-Hant': 'zh-Hant-TW',
0bd558a0
C
59 'zh-TW': 'zh-Hant-TW',
60 'zh': 'zh-Hans-CN'
74b7c6d4
C
61}
62
63export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
64 .concat(Object.keys(I18N_LOCALE_ALIAS))
65
989e526a
C
66export function getDefaultLocale () {
67 return 'en-US'
68}
69
e945b184 70export function isDefaultLocale (locale: string) {
74b7c6d4 71 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
e945b184
C
72}
73
3dfa8494 74export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
a1587156
C
75 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
76 // eslint-disable-next-line
3dfa8494
C
77 return translations && translations[str] ? translations[str] : str
78}
79
8afc19a6 80const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
989e526a 81export function is18nPath (path: string) {
bdd428a6 82 return possiblePaths.includes(path)
989e526a
C
83}
84
989e526a 85export function is18nLocale (locale: string) {
bdd428a6 86 return POSSIBLE_LOCALES.includes(locale)
74b7c6d4
C
87}
88
89export function getCompleteLocale (locale: string) {
90 if (!locale) return locale
91
92 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
93
94 return locale
989e526a
C
95}
96
9f164722 97export function getShortLocale (locale: string) {
bdd428a6 98 if (locale.includes('-') === false) return locale
9f164722
C
99
100 return locale.split('-')[0]
101}
102
989e526a 103export function buildFileLocale (locale: string) {
350131cb 104 return getCompleteLocale(locale)
989e526a 105}