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