Skip to content

Commit 8ad167f

Browse files
committed
refactor: centralize Clerk localization handling in AppConfig
1 parent 4308d16 commit 8ad167f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/app/[locale]/(auth)/layout.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { routing } from '@/libs/i18nRouting';
2-
import { enUS, frFR } from '@clerk/localizations';
2+
import { ClerkLocalizations } from '@/utils/AppConfig';
33
import { ClerkProvider } from '@clerk/nextjs';
44
import { setRequestLocale } from 'next-intl/server';
55

@@ -10,16 +10,12 @@ export default async function AuthLayout(props: {
1010
const { locale } = await props.params;
1111
setRequestLocale(locale);
1212

13-
let clerkLocale = enUS;
13+
const clerkLocale = ClerkLocalizations.supportedLocales[locale] ?? ClerkLocalizations.defaultLocale;
1414
let signInUrl = '/sign-in';
1515
let signUpUrl = '/sign-up';
1616
let dashboardUrl = '/dashboard';
1717
let afterSignOutUrl = '/';
1818

19-
if (locale === 'fr') {
20-
clerkLocale = frFR;
21-
}
22-
2319
if (locale !== routing.defaultLocale) {
2420
signInUrl = `/${locale}${signInUrl}`;
2521
signUpUrl = `/${locale}${signUpUrl}`;

src/utils/AppConfig.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import type { LocalizationResource } from '@clerk/types';
12
import type { LocalePrefixMode } from 'next-intl/routing';
3+
import { enUS, frFR } from '@clerk/localizations';
24

35
const localePrefix: LocalePrefixMode = 'as-needed';
46

@@ -9,3 +11,13 @@ export const AppConfig = {
911
defaultLocale: 'en',
1012
localePrefix,
1113
};
14+
15+
const supportedLocales: Record<string, LocalizationResource> = {
16+
en: enUS,
17+
fr: frFR,
18+
};
19+
20+
export const ClerkLocalizations = {
21+
defaultLocale: enUS,
22+
supportedLocales,
23+
};

0 commit comments

Comments
 (0)