From 36d3afd62fa3a25d526e4f75f3ef976d04cbfebe Mon Sep 17 00:00:00 2001 From: seriousm4x Date: Tue, 3 Oct 2023 21:34:39 +0200 Subject: [PATCH] fix: date-fns not loading locales correctly --- frontend/.typesafe-i18n.json | 1 - frontend/src/lib/components/DeviceCard.svelte | 12 +++++++++--- frontend/src/lib/i18n/i18n-types.ts | 2 +- frontend/src/lib/i18n/i18n-util.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/.typesafe-i18n.json b/frontend/.typesafe-i18n.json index cd3dd171..e2aae86e 100644 --- a/frontend/.typesafe-i18n.json +++ b/frontend/.typesafe-i18n.json @@ -1,6 +1,5 @@ { "adapter": "svelte", "$schema": "https://unpkg.com/typesafe-i18n@5.26.2/schema/typesafe-i18n.json", - "baseLocale": "en-US", "outputPath": "./src/lib/i18n/" } diff --git a/frontend/src/lib/components/DeviceCard.svelte b/frontend/src/lib/components/DeviceCard.svelte index d477c9fe..bcc4a011 100644 --- a/frontend/src/lib/components/DeviceCard.svelte +++ b/frontend/src/lib/components/DeviceCard.svelte @@ -63,15 +63,21 @@ $: if ($locale !== undefined) { (async () => { switch ($locale) { - case 'de' || 'de-DE': + case 'de': + case 'de-DE': dateFnsLocale = (await import('date-fns/locale/de/index.js')).default; break; - case 'en' || 'en-US': + case 'en': + case 'en-US': dateFnsLocale = (await import('date-fns/locale/en-US/index.js')).default; break; - case 'pt' || 'pt-PT': + case 'pt': + case 'pt-PT': dateFnsLocale = (await import('date-fns/locale/pt/index.js')).default; break; + default: + dateFnsLocale = (await import('date-fns/locale/en-US/index.js')).default; + break; } })(); } diff --git a/frontend/src/lib/i18n/i18n-types.ts b/frontend/src/lib/i18n/i18n-types.ts index df024748..08f45eea 100644 --- a/frontend/src/lib/i18n/i18n-types.ts +++ b/frontend/src/lib/i18n/i18n-types.ts @@ -7,7 +7,7 @@ import type { } from 'typesafe-i18n'; export type BaseTranslation = BaseTranslationType; -export type BaseLocale = 'en-US'; +export type BaseLocale = 'en'; export type Locales = 'de' | 'de-DE' | 'en' | 'en-US' | 'pt' | 'pt-PT'; diff --git a/frontend/src/lib/i18n/i18n-util.ts b/frontend/src/lib/i18n/i18n-util.ts index bc8959b0..a1f0f5df 100644 --- a/frontend/src/lib/i18n/i18n-util.ts +++ b/frontend/src/lib/i18n/i18n-util.ts @@ -12,7 +12,7 @@ import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'; import { initExtendDictionary } from 'typesafe-i18n/utils'; import type { Formatters, Locales, Translations, TranslationFunctions } from './i18n-types'; -export const baseLocale: Locales = 'en-US'; +export const baseLocale: Locales = 'en'; export const locales: Locales[] = ['de', 'de-DE', 'en', 'en-US', 'pt', 'pt-PT'];