]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/core-utils/i18n/i18n.ts
add client.videos.upload.maxChunkSize config (#4857)
[github/Chocobozzz/PeerTube.git] / shared / core-utils / i18n / i18n.ts
1 export const LOCALE_FILES = [ 'player', 'server' ]
2
3 export const I18N_LOCALES = {
4 // Always first to avoid issues when using express acceptLanguages function when no accept language header is set
5 'en-US': 'English',
6
7 'ar': 'العربية',
8 'ca-ES': 'Català',
9 'cs-CZ': 'Čeština',
10 'de-DE': 'Deutsch',
11 'el-GR': 'ελληνικά',
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 'gl-ES': 'galego',
19 'hu-HU': 'magyar',
20 'fa-IR': 'فارسی',
21 'it-IT': 'Italiano',
22 'ja-JP': '日本語',
23 'kab': 'Taqbaylit',
24 'nl-NL': 'Nederlands',
25 'oc': 'Occitan',
26 'pl-PL': 'Polski',
27 'pt-BR': 'Português (Brasil)',
28 'pt-PT': 'Português (Portugal)',
29 'ru-RU': 'русский',
30 'sq': 'Shqip',
31 'sv-SE': 'Svenska',
32 'nn': 'norsk nynorsk',
33 'nb-NO': 'norsk bokmål',
34 'th-TH': 'ไทย',
35 'vi-VN': 'Tiếng Việt',
36 'zh-Hans-CN': '简体中文(中国)',
37 'zh-Hant-TW': '繁體中文(台灣)'
38 }
39
40 const I18N_LOCALE_ALIAS = {
41 'ar-001': 'ar',
42 'ca': 'ca-ES',
43 'cs': 'cs-CZ',
44 'de': 'de-DE',
45 'el': 'el-GR',
46 'en': 'en-US',
47 'es': 'es-ES',
48 'eu': 'eu-ES',
49 'fi': 'fi-FI',
50 'gl': 'gl-ES',
51 'fa': 'fa-IR',
52 'fr': 'fr-FR',
53 'hu': 'hu-HU',
54 'it': 'it-IT',
55 'ja': 'ja-JP',
56 'nl': 'nl-NL',
57 'pl': 'pl-PL',
58 'pt': 'pt-BR',
59 'nb': 'nb-NO',
60 'ru': 'ru-RU',
61 'sv': 'sv-SE',
62 'th': 'th-TH',
63 'vi': 'vi-VN',
64 'zh-CN': 'zh-Hans-CN',
65 'zh-Hans': 'zh-Hans-CN',
66 'zh-Hant': 'zh-Hant-TW',
67 'zh-TW': 'zh-Hant-TW',
68 'zh': 'zh-Hans-CN'
69 }
70
71 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
72 .concat(Object.keys(I18N_LOCALE_ALIAS))
73
74 export function getDefaultLocale () {
75 return 'en-US'
76 }
77
78 export function isDefaultLocale (locale: string) {
79 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
80 }
81
82 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
83 if (!translations || !translations[str]) return str
84
85 return translations[str]
86 }
87
88 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
89 export function is18nPath (path: string) {
90 return possiblePaths.includes(path)
91 }
92
93 export function is18nLocale (locale: string) {
94 return POSSIBLE_LOCALES.includes(locale)
95 }
96
97 export function getCompleteLocale (locale: string) {
98 if (!locale) return locale
99
100 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
101
102 return locale
103 }
104
105 export function getShortLocale (locale: string) {
106 if (locale.includes('-') === false) return locale
107
108 return locale.split('-')[0]
109 }
110
111 export function buildFileLocale (locale: string) {
112 return getCompleteLocale(locale)
113 }