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