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