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