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