]>
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 | ||
4c61660a | 7 | // Keep it alphabetically sorted |
d10538b4 | 8 | 'ar': 'العربية', |
7f768064 Q |
9 | 'ca-ES': 'Català', |
10 | 'cs-CZ': 'Čeština', | |
fb9e6cb0 | 11 | 'de-DE': 'Deutsch', |
0df21c79 | 12 | 'el-GR': 'ελληνικά', |
0df21c79 C |
13 | 'eo': 'Esperanto', |
14 | 'es-ES': 'Español', | |
15 | 'eu-ES': 'Euskara', | |
4c61660a | 16 | 'fa-IR': 'فارسی', |
f069b901 | 17 | 'fi-FI': 'Suomi', |
0df21c79 C |
18 | 'fr-FR': 'Français', |
19 | 'gd': 'Gàidhlig', | |
f069b901 C |
20 | 'gl-ES': 'Galego', |
21 | 'hr': 'Hrvatski', | |
22 | 'hu-HU': 'Magyar', | |
4c61660a | 23 | 'is': 'Íslenska', |
d7aea77b | 24 | 'it-IT': 'Italiano', |
0df21c79 | 25 | 'ja-JP': '日本語', |
0bd558a0 | 26 | 'kab': 'Taqbaylit', |
f069b901 | 27 | 'nb-NO': 'Norsk bokmål', |
8137c8b9 | 28 | 'nl-NL': 'Nederlands', |
f069b901 | 29 | 'nn': 'Norsk nynorsk', |
2a39506c | 30 | 'oc': 'Occitan', |
0df21c79 | 31 | 'pl-PL': 'Polski', |
a9155ee6 | 32 | 'pt-BR': 'Português (Brasil)', |
8137c8b9 | 33 | 'pt-PT': 'Português (Portugal)', |
f069b901 | 34 | 'ru-RU': 'Pусский', |
f45aa01a C |
35 | 'sq': 'Shqip', |
36 | 'sv-SE': 'Svenska', | |
0df21c79 | 37 | 'th-TH': 'ไทย', |
4c1ce3d4 | 38 | 'tok': 'Toki Pona', |
4c61660a C |
39 | 'uk-UA': 'украї́нська мо́ва', |
40 | 'vi-VN': 'Tiếng Việt', | |
0df21c79 C |
41 | 'zh-Hans-CN': '简体中文(中国)', |
42 | 'zh-Hant-TW': '繁體中文(台灣)' | |
989e526a C |
43 | } |
44 | ||
4c61660a | 45 | // Keep it alphabetically sorted |
c199c427 | 46 | const I18N_LOCALE_ALIAS = { |
d10538b4 | 47 | 'ar-001': 'ar', |
a55e5579 | 48 | 'ca': 'ca-ES', |
fb9e6cb0 C |
49 | 'cs': 'cs-CZ', |
50 | 'de': 'de-DE', | |
1fe654e0 | 51 | 'el': 'el-GR', |
0df21c79 | 52 | 'en': 'en-US', |
a9155ee6 | 53 | 'es': 'es-ES', |
0df21c79 | 54 | 'eu': 'eu-ES', |
55f0a7a7 | 55 | 'fa': 'fa-IR', |
4c61660a | 56 | 'fi': 'fi-FI', |
0df21c79 | 57 | 'fr': 'fr-FR', |
4c61660a | 58 | 'gl': 'gl-ES', |
0df21c79 | 59 | 'hu': 'hu-HU', |
0bd558a0 C |
60 | 'it': 'it-IT', |
61 | 'ja': 'ja-JP', | |
4c61660a | 62 | 'nb': 'nb-NO', |
0df21c79 | 63 | 'nl': 'nl-NL', |
d7aea77b | 64 | 'pl': 'pl-PL', |
1fe654e0 | 65 | 'pt': 'pt-BR', |
8137c8b9 | 66 | 'ru': 'ru-RU', |
0df21c79 C |
67 | 'sv': 'sv-SE', |
68 | 'th': 'th-TH', | |
4c61660a | 69 | 'uk': 'uk-UA', |
0bd558a0 | 70 | 'vi': 'vi-VN', |
f69ec5f3 | 71 | 'zh-CN': 'zh-Hans-CN', |
0bd558a0 | 72 | 'zh-Hans': 'zh-Hans-CN', |
1fe654e0 | 73 | 'zh-Hant': 'zh-Hant-TW', |
0bd558a0 C |
74 | 'zh-TW': 'zh-Hant-TW', |
75 | 'zh': 'zh-Hans-CN' | |
74b7c6d4 C |
76 | } |
77 | ||
3b504f6e | 78 | export const POSSIBLE_LOCALES = (Object.keys(I18N_LOCALES) as string[]).concat(Object.keys(I18N_LOCALE_ALIAS)) |
74b7c6d4 | 79 | |
989e526a C |
80 | export function getDefaultLocale () { |
81 | return 'en-US' | |
82 | } | |
83 | ||
e945b184 | 84 | export function isDefaultLocale (locale: string) { |
74b7c6d4 | 85 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) |
e945b184 C |
86 | } |
87 | ||
3dfa8494 | 88 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { |
99b75748 | 89 | if (!translations?.[str]) return str |
67baf647 C |
90 | |
91 | return translations[str] | |
3dfa8494 C |
92 | } |
93 | ||
8afc19a6 | 94 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) |
989e526a | 95 | export function is18nPath (path: string) { |
bdd428a6 | 96 | return possiblePaths.includes(path) |
989e526a C |
97 | } |
98 | ||
989e526a | 99 | export function is18nLocale (locale: string) { |
bdd428a6 | 100 | return POSSIBLE_LOCALES.includes(locale) |
74b7c6d4 C |
101 | } |
102 | ||
103 | export function getCompleteLocale (locale: string) { | |
104 | if (!locale) return locale | |
105 | ||
106 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
107 | ||
108 | return locale | |
989e526a C |
109 | } |
110 | ||
9f164722 | 111 | export function getShortLocale (locale: string) { |
bdd428a6 | 112 | if (locale.includes('-') === false) return locale |
9f164722 C |
113 | |
114 | return locale.split('-')[0] | |
115 | } | |
116 | ||
989e526a | 117 | export function buildFileLocale (locale: string) { |
350131cb | 118 | return getCompleteLocale(locale) |
989e526a | 119 | } |