]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/models/i18n/i18n.ts
Merge branch 'release/2.1.0' into develop
[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',
0df21c79 36 'en': 'en-US',
a9155ee6 37 'es': 'es-ES',
0df21c79 38 'eu': 'eu-ES',
82054691 39 'fi': 'fi-FI',
0df21c79
C
40 'fr': 'fr-FR',
41 'hu': 'hu-HU',
42 'nl': 'nl-NL',
d7aea77b 43 'pl': 'pl-PL',
0df21c79 44 'pt': 'pt-PT',
8137c8b9 45 'ru': 'ru-RU',
0df21c79
C
46 'sv': 'sv-SE',
47 'th': 'th-TH',
f69ec5f3
C
48 'zh': 'zh-Hans-CN',
49 'zh-CN': 'zh-Hans-CN',
50 'zh-TW': 'zh-Hant-TW'
74b7c6d4
C
51}
52
53export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
54 .concat(Object.keys(I18N_LOCALE_ALIAS))
55
989e526a
C
56export function getDefaultLocale () {
57 return 'en-US'
58}
59
e945b184 60export function isDefaultLocale (locale: string) {
74b7c6d4 61 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
e945b184
C
62}
63
3dfa8494 64export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
a1587156
C
65 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
66 // eslint-disable-next-line
3dfa8494
C
67 return translations && translations[str] ? translations[str] : str
68}
69
8afc19a6 70const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
989e526a
C
71export function is18nPath (path: string) {
72 return possiblePaths.indexOf(path) !== -1
73}
74
989e526a 75export function is18nLocale (locale: string) {
74b7c6d4
C
76 return POSSIBLE_LOCALES.indexOf(locale) !== -1
77}
78
79export function getCompleteLocale (locale: string) {
80 if (!locale) return locale
81
82 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
83
84 return locale
989e526a
C
85}
86
9f164722
C
87export function getShortLocale (locale: string) {
88 if (locale.indexOf('-') === -1) return locale
89
90 return locale.split('-')[0]
91}
92
989e526a 93export function buildFileLocale (locale: string) {
350131cb 94 return getCompleteLocale(locale)
989e526a 95}