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