From 989e526abf0c0dd7958deb630df009608561bb67 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 31 May 2018 18:12:15 +0200 Subject: Prepare i18n files --- shared/models/i18n/i18n.ts | 30 ++++++++++++++++++++++++++++++ shared/models/i18n/index.ts | 1 + 2 files changed, 31 insertions(+) create mode 100644 shared/models/i18n/i18n.ts create mode 100644 shared/models/i18n/index.ts (limited to 'shared/models/i18n') diff --git a/shared/models/i18n/i18n.ts b/shared/models/i18n/i18n.ts new file mode 100644 index 000000000..2d3a1d3e2 --- /dev/null +++ b/shared/models/i18n/i18n.ts @@ -0,0 +1,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('-', '_') +} diff --git a/shared/models/i18n/index.ts b/shared/models/i18n/index.ts new file mode 100644 index 000000000..8f7cbe2c7 --- /dev/null +++ b/shared/models/i18n/index.ts @@ -0,0 +1 @@ +export * from './i18n' -- cgit v1.2.3