blob: 4d50bc36ea73edca5e4130c1766ec08655bf01a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
export const I18N_LOCALES = {
'en-US': 'English (US)',
fr: 'French'
}
export function getDefaultLocale () {
return 'en-US'
}
export function isDefaultLocale (locale: string) {
return locale === getDefaultLocale()
}
const possiblePaths = Object.keys(I18N_LOCALES).map(l => '/' + l)
export function is18nPath (path: string) {
return possiblePaths.indexOf(path) !== -1
}
const possibleLanguages = Object.keys(I18N_LOCALES)
export function is18nLocale (locale: string) {
return possibleLanguages.indexOf(locale) !== -1
}
// Only use in dev mode, so relax
// In production, the locale always match with a I18N_LANGUAGES key
export function buildFileLocale (locale: string) {
if (!is18nLocale(locale)) {
// Some working examples for development purpose
if (locale.split('-')[ 0 ] === 'en') return 'en_US'
else if (locale === 'fr') return 'fr'
}
return locale.replace('-', '_')
}
|