fix(web): switch i18n.ts to await requestLocale (next-intl 3.22+)
The `locale` parameter passed to getRequestConfig is deprecated; next-intl now provides `requestLocale` as a Promise. Resolve it at the top of the callback, fall back to defaultLocale when the requested one isn't supported, and return both locale and messages. Removes the per-request deprecation warning in dev/E2E logs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4349c395e3
commit
e931132342
1 file changed
+6
-6
@@ -1,4 +1,3 @@
|
|||||||
import { notFound } from 'next/navigation';
|
|
||||||
import { getRequestConfig } from 'next-intl/server';
|
import { getRequestConfig } from 'next-intl/server';
|
||||||
|
|
||||||
export const locales = ['it'] as const;
|
export const locales = ['it'] as const;
|
||||||
@@ -6,13 +5,14 @@ export const defaultLocale = 'it' as const;
|
|||||||
|
|
||||||
export type Locale = (typeof locales)[number];
|
export type Locale = (typeof locales)[number];
|
||||||
|
|
||||||
export default getRequestConfig(async ({ locale }) => {
|
export default getRequestConfig(async ({ requestLocale }) => {
|
||||||
if (!locales.includes(locale as Locale)) {
|
const requested = await requestLocale;
|
||||||
notFound();
|
const locale: Locale = locales.includes(requested as Locale)
|
||||||
}
|
? (requested as Locale)
|
||||||
|
: defaultLocale;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
locale: locale as Locale,
|
locale,
|
||||||
messages: (await import(`../messages/${locale}.json`)).default,
|
messages: (await import(`../messages/${locale}.json`)).default,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user