aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/models/i18n/i18n.ts
blob: 2d3a1d3e274fd65a61141a304d3eb92474f87c8d (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
export const I18N_LOCALES = {
  'en-US': 'English (US)',
  fr: 'French'
}

export function getDefaultLocale () {
  return 'en-US'
}

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('-', '_')
}