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