]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/i18n/i18n.ts
14b02a01d57129933ae6a41e8e87241940769932
[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 }
7
8 const I18N_LOCALE_ALIAS = {
9 'en': 'en-US',
10 'fr': 'fr-FR'
11 }
12
13 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
14 .concat(Object.keys(I18N_LOCALE_ALIAS))
15
16 export function getDefaultLocale () {
17 return 'en-US'
18 }
19
20 export function isDefaultLocale (locale: string) {
21 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
22 }
23
24 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
25 export function is18nPath (path: string) {
26 return possiblePaths.indexOf(path) !== -1
27 }
28
29 export function is18nLocale (locale: string) {
30 return POSSIBLE_LOCALES.indexOf(locale) !== -1
31 }
32
33 export function getCompleteLocale (locale: string) {
34 if (!locale) return locale
35
36 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
37
38 return locale
39 }
40
41 export function getShortLocale (locale: string) {
42 if (locale.indexOf('-') === -1) return locale
43
44 return locale.split('-')[0]
45 }
46
47 export function buildFileLocale (locale: string) {
48 const completeLocale = getCompleteLocale(locale)
49
50 return completeLocale.replace('-', '_')
51 }