aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/models/i18n/i18n.ts
blob: 4d50bc36ea73edca5e4130c1766ec08655bf01a5 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                     



                                                  




















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