diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-06 14:58:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-07 08:28:14 +0200 |
commit | bd45d503e5d007e730f4e81dccd7e7864c9a85cc (patch) | |
tree | b78df768b8253ba401232c17da940cea016c9960 /shared/core-utils/i18n | |
parent | 583eb04b541175035d6d452ca626a96ebf2b7437 (diff) | |
download | PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.gz PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.zst PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.zip |
Reorganize shared models
Diffstat (limited to 'shared/core-utils/i18n')
-rw-r--r-- | shared/core-utils/i18n/i18n.ts | 105 | ||||
-rw-r--r-- | shared/core-utils/i18n/index.ts | 1 |
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 @@ | |||
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 | '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 | |||
35 | const 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 | |||
63 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | ||
64 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | ||
65 | |||
66 | export function getDefaultLocale () { | ||
67 | return 'en-US' | ||
68 | } | ||
69 | |||
70 | export function isDefaultLocale (locale: string) { | ||
71 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | ||
72 | } | ||
73 | |||
74 | export 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 | |||
80 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | ||
81 | export function is18nPath (path: string) { | ||
82 | return possiblePaths.includes(path) | ||
83 | } | ||
84 | |||
85 | export function is18nLocale (locale: string) { | ||
86 | return POSSIBLE_LOCALES.includes(locale) | ||
87 | } | ||
88 | |||
89 | export 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 | |||
97 | export function getShortLocale (locale: string) { | ||
98 | if (locale.includes('-') === false) return locale | ||
99 | |||
100 | return locale.split('-')[0] | ||
101 | } | ||
102 | |||
103 | export 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' | |||