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