Skip to content

Commit 9a39b01

Browse files
authored
feat(i18n): add en-US locale with American date formatting (#1262)
feat(i18n): add en-US locale with American date formatting - Rename 'en' to 'en-GB' for explicit UK locale (DD/MM/YYYY) - Add 'en-US' locale for American date formatting (MM/DD/YYYY) - Both locales share the same English translations - Update getDateFnsLocale to support exact locale matching
1 parent df95a39 commit 9a39b01

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/app-builder/src/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
139139
<AgnosticNavigationContext.Provider value={navigate}>
140140
<AuthenticityTokenProvider token={loaderData?.['csrf'] ?? ''}>
141141
<FormatContext.Provider
142-
value={{ locale: loaderData?.locale ?? 'en', timezone: loaderData?.timezone ?? 'UTC' }}
142+
value={{ locale: loaderData?.locale ?? 'en-GB', timezone: loaderData?.timezone ?? 'UTC' }}
143143
>
144144
<Tooltip.Provider>{children}</Tooltip.Provider>
145145
</FormatContext.Provider>

packages/app-builder/src/services/i18n/i18n-config.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import 'cronstrue/locales/fr.js';
44
import { type Locale } from 'date-fns/locale';
55
import { ar } from 'date-fns/locale/ar';
66
import { enGB } from 'date-fns/locale/en-GB';
7+
import { enUS } from 'date-fns/locale/en-US';
78
import { fr } from 'date-fns/locale/fr';
89
import { type InitOptions } from 'i18next';
910

1011
export const defaultNS = 'common';
1112

1213
// When adding a new supported lng, add corresponding cronstrue locale above too
13-
export const supportedLngs = ['en', 'fr', 'ar'] as const;
14+
export const supportedLngs = ['en-GB', 'en-US', 'fr', 'ar'] as const;
1415
export const languageNames: Record<(typeof supportedLngs)[number], { dir: 'ltr' | 'rtl'; name: string }> = {
15-
en: { dir: 'ltr', name: 'English' },
16+
'en-GB': { dir: 'ltr', name: 'English (UK)' },
17+
'en-US': { dir: 'ltr', name: 'English (US)' },
1618
fr: { dir: 'ltr', name: 'Français' },
1719
ar: { dir: 'rtl', name: 'العربية' },
1820
};
19-
const fallbackLng = 'en';
21+
const fallbackLng = 'en-GB';
2022

2123
export const i18nConfig = {
2224
interpolation: {
@@ -33,13 +35,19 @@ export const i18nConfig = {
3335
} satisfies InitOptions;
3436

3537
const dateFnsLocales = {
36-
en: enGB,
38+
'en-GB': enGB,
39+
'en-US': enUS,
3740
fr: fr,
3841
ar: ar,
3942
} satisfies Record<(typeof supportedLngs)[number], Locale>;
4043

4144
export function getDateFnsLocale(locale: string): Locale {
42-
// Extract language code (e.g., "fr" from "fr-FR")
45+
// First try exact match (e.g., "en-US"), then fallback to language code (e.g., "en")
46+
const exactMatch = supportedLngs.find((lng) => locale === lng);
47+
if (exactMatch) {
48+
return dateFnsLocales[exactMatch];
49+
}
50+
4351
const lang = locale.split('-')[0];
4452
const supportedLocale = supportedLngs.find((lng) => lang === lng) ?? fallbackLng;
4553
return dateFnsLocales[supportedLocale];

packages/app-builder/src/services/i18n/resources/resources.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { en } from './en.server';
44
import { fr } from './fr.server';
55

66
export const resources = {
7-
en,
7+
'en-GB': en,
8+
'en-US': en, // Reuse English translations, date/number formatting differs via locale
89
fr,
910
ar,
1011
} satisfies Record<(typeof supportedLngs)[number], typeof en>;

0 commit comments

Comments
 (0)