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