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