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