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 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 shared/models/i18n/i18n.ts (limited to 'shared/models/i18n/i18n.ts') 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('-', '_') +} -- cgit v1.2.3