aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils/i18n
diff options
context:
space:
mode:
Diffstat (limited to 'shared/core-utils/i18n')
-rw-r--r--shared/core-utils/i18n/i18n.ts105
-rw-r--r--shared/core-utils/i18n/index.ts1
2 files changed, 106 insertions, 0 deletions
diff --git a/shared/core-utils/i18n/i18n.ts b/shared/core-utils/i18n/i18n.ts
new file mode 100644
index 000000000..9ad0f456d
--- /dev/null
+++ b/shared/core-utils/i18n/i18n.ts
@@ -0,0 +1,105 @@
1export const LOCALE_FILES = [ 'player', 'server' ]
2
3export 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 'hu-HU': 'magyar',
19 'it-IT': 'Italiano',
20 'ja-JP': '日本語',
21 'kab': 'Taqbaylit',
22 'nl-NL': 'Nederlands',
23 'oc': 'Occitan',
24 'pl-PL': 'Polski',
25 'pt-BR': 'Português (Brasil)',
26 'pt-PT': 'Português (Portugal)',
27 'ru-RU': 'русский',
28 'sv-SE': 'svenska',
29 'th-TH': 'ไทย',
30 'vi-VN': 'Tiếng Việt',
31 'zh-Hans-CN': '简体中文(中国)',
32 'zh-Hant-TW': '繁體中文(台灣)'
33}
34
35const I18N_LOCALE_ALIAS = {
36 'ar-001': 'ar',
37 'ca': 'ca-ES',
38 'cs': 'cs-CZ',
39 'de': 'de-DE',
40 'el': 'el-GR',
41 'en': 'en-US',
42 'es': 'es-ES',
43 'eu': 'eu-ES',
44 'fi': 'fi-FI',
45 'fr': 'fr-FR',
46 'hu': 'hu-HU',
47 'it': 'it-IT',
48 'ja': 'ja-JP',
49 'nl': 'nl-NL',
50 'pl': 'pl-PL',
51 'pt': 'pt-BR',
52 'ru': 'ru-RU',
53 'sv': 'sv-SE',
54 'th': 'th-TH',
55 'vi': 'vi-VN',
56 'zh-CN': 'zh-Hans-CN',
57 'zh-Hans': 'zh-Hans-CN',
58 'zh-Hant': 'zh-Hant-TW',
59 'zh-TW': 'zh-Hant-TW',
60 'zh': 'zh-Hans-CN'
61}
62
63export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
64 .concat(Object.keys(I18N_LOCALE_ALIAS))
65
66export function getDefaultLocale () {
67 return 'en-US'
68}
69
70export function isDefaultLocale (locale: string) {
71 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
72}
73
74export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
75 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
76 // eslint-disable-next-line
77 return translations && translations[str] ? translations[str] : str
78}
79
80const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
81export function is18nPath (path: string) {
82 return possiblePaths.includes(path)
83}
84
85export function is18nLocale (locale: string) {
86 return POSSIBLE_LOCALES.includes(locale)
87}
88
89export function getCompleteLocale (locale: string) {
90 if (!locale) return locale
91
92 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
93
94 return locale
95}
96
97export function getShortLocale (locale: string) {
98 if (locale.includes('-') === false) return locale
99
100 return locale.split('-')[0]
101}
102
103export function buildFileLocale (locale: string) {
104 return getCompleteLocale(locale)
105}
diff --git a/shared/core-utils/i18n/index.ts b/shared/core-utils/i18n/index.ts
new file mode 100644
index 000000000..8f7cbe2c7
--- /dev/null
+++ b/shared/core-utils/i18n/index.ts
@@ -0,0 +1 @@
export * from './i18n'