Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add support for all date locales in react dashboard
Damian Legawiec82e7336eef73
diff --git a/packages/dashboard-ui/src/lib/date-locale.ts b/packages/dashboard-ui/src/lib/date-locale.tsindex c626f5f21e..d14b6d61c2 100644--- a/packages/dashboard-ui/src/lib/date-locale.ts+++ b/packages/dashboard-ui/src/lib/date-locale.ts@@ -1,19 +1,29 @@-import { de, enUS, fr, pl } from 'date-fns/locale'+import * as dateFnsLocales from 'date-fns/locale'import i18n from 'i18next'import type { Locale } from 'react-day-picker'-// Maps the admin UI language (i18next) to a date-fns locale so calendars and-// date formatting render month/weekday names in the chosen language. Falls-// back to English. Extend this map whenever a new UI locale bundle ships.-const DATE_LOCALES: Record<string, Locale> = {- en: enUS,- de,- fr,- pl,+// date-fns ships ~96 locales; we resolve one by the active i18n language code+// instead of maintaining a hand-kept map (which silently drifted to English+// whenever a new UI bundle shipped without a matching entry here). The whole+// locale set is imported, so any language a translation bundle adds is covered+// with no edit to this file.+const LOCALES = dateFnsLocales as unknown as Record<string, Locale>++// i18next codes are BCP-47-ish (`en`, `pt-BR`, `zh-CN`); date-fns export names+// are camelCase (`enUS`, `ptBR`, `zhCN`). Convert `-x` → `X` to match.+function dateFnsKey(code: string): string {+ return code.replace(/-(\w)/g, (_, c: string) => c.toUpperCase())+}++// Resolve a date-fns Locale for an i18n language code. Tries the exact code,+// then the base language (`pt-BR` → `pt`), and finally falls back to `enUS`.+// `en` has no bare date-fns export, so it resolves through the fallback.+function resolveDateLocale(code: string): Locale {+ const base = code.split('-')[0]+ return LOCALES[dateFnsKey(code)] ?? LOCALES[base] ?? LOCALES.enUS}/** date-fns locale for the active admin UI language (falls back to English). */export function activeDateLocale(): Locale {- const lang = i18n.language ?? 'en'- return DATE_LOCALES[lang] ?? DATE_LOCALES[lang.split('-')[0]] ?? enUS+ return resolveDateLocale(i18n.language ?? 'en')}