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';
|
||||
|
||||
export const locales = ['it'] as const;
|
||||
@@ -6,13 +5,14 @@ export const defaultLocale = 'it' as const;
|
||||
|
||||
export type Locale = (typeof locales)[number];
|
||||
|
||||
export default getRequestConfig(async ({ locale }) => {
|
||||
if (!locales.includes(locale as Locale)) {
|
||||
notFound();
|
||||
}
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
const requested = await requestLocale;
|
||||
const locale: Locale = locales.includes(requested as Locale)
|
||||
? (requested as Locale)
|
||||
: defaultLocale;
|
||||
|
||||
return {
|
||||
locale: locale as Locale,
|
||||
locale,
|
||||
messages: (await import(`../messages/${locale}.json`)).default,
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user