]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/i18n/i18n.ts
Add Nederlands and Português (Portugal)
[github/Chocobozzz/PeerTube.git] / shared / models / i18n / i18n.ts
1 export const LOCALE_FILES = [ 'player', 'server' ]
2
3 export const I18N_LOCALES = {
4 'en-US': 'English',
5 'fr-FR': 'Français',
6 'eu-ES': 'Euskara',
7 'ca-ES': 'Català',
8 'cs-CZ': 'Čeština',
9 'eo': 'Esperanto',
10 'de-DE': 'Deutsch',
11 'it-IT': 'Italiano',
12 'nl-NL': 'Nederlands',
13 'es-ES': 'Español',
14 'oc': 'Occitan',
15 'zh-Hant-TW': '繁體中文(台灣)',
16 'pt-BR': 'Português (Brasil)',
17 'pt-PT': 'Português (Portugal)',
18 'sv-SE': 'svenska',
19 'pl-PL': 'Polski',
20 'ru-RU': 'русский',
21 'zh-Hans-CN': '简体中文(中国)'
22 }
23
24 const I18N_LOCALE_ALIAS = {
25 'en': 'en-US',
26 'fr': 'fr-FR',
27 'eu': 'eu-ES',
28 'ca': 'ca-ES',
29 'cs': 'cs-CZ',
30 'de': 'de-DE',
31 'es': 'es-ES',
32 'pt': 'pt-PT',
33 'sv': 'sv-SE',
34 'pl': 'pl-PL',
35 'ru': 'ru-RU',
36 'nl': 'nl-NL',
37 'zh': 'zh-Hans-CN'
38 }
39
40 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
41 .concat(Object.keys(I18N_LOCALE_ALIAS))
42
43 export function getDefaultLocale () {
44 return 'en-US'
45 }
46
47 export function isDefaultLocale (locale: string) {
48 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
49 }
50
51 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
52 return translations && translations[str] ? translations[str] : str
53 }
54
55 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
56 export function is18nPath (path: string) {
57 return possiblePaths.indexOf(path) !== -1
58 }
59
60 export function is18nLocale (locale: string) {
61 return POSSIBLE_LOCALES.indexOf(locale) !== -1
62 }
63
64 export function getCompleteLocale (locale: string) {
65 if (!locale) return locale
66
67 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
68
69 return locale
70 }
71
72 export function getShortLocale (locale: string) {
73 if (locale.indexOf('-') === -1) return locale
74
75 return locale.split('-')[0]
76 }
77
78 export function buildFileLocale (locale: string) {
79 const completeLocale = getCompleteLocale(locale)
80
81 return completeLocale.replace(/-/g, '_')
82 }