Skip to content

Commit 344da5b

Browse files
amannnovflowd
andauthored
chore: Upgrade next-intl to 3.24, migrate deprecated APIs (#7177)
* chore: Upgrade next-intl to 3.24, migrate deprecated APIs * reduce changes * revert another change * fix: Read locale from params in layout * address review points --------- Co-authored-by: Claudio W <[email protected]>
1 parent 9ad96f4 commit 344da5b

File tree

8 files changed

+90
-72
lines changed

8 files changed

+90
-72
lines changed

apps/site/app/[locale]/[[...path]]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setContext, setTags } from '@sentry/nextjs';
22
import { notFound, redirect } from 'next/navigation';
3-
import { unstable_setRequestLocale } from 'next-intl/server';
3+
import { setRequestLocale } from 'next-intl/server';
44
import type { FC } from 'react';
55

66
import { setClientContext } from '@/client-context';
@@ -69,7 +69,7 @@ const getPage: FC<DynamicParams> = async ({ params }) => {
6969

7070
if (!availableLocaleCodes.includes(locale)) {
7171
// Forces the current locale to be the Default Locale
72-
unstable_setRequestLocale(defaultLocale.code);
72+
setRequestLocale(defaultLocale.code);
7373

7474
if (!allLocaleCodes.includes(locale)) {
7575
// when the locale is not listed in the locales, return NotFound
@@ -82,7 +82,7 @@ const getPage: FC<DynamicParams> = async ({ params }) => {
8282
}
8383

8484
// Configures the current Locale to be the given Locale of the Request
85-
unstable_setRequestLocale(locale);
85+
setRequestLocale(locale);
8686

8787
// Gets the current full pathname for a given path
8888
const pathname = dynamicRouter.getPathname(path);

apps/site/app/[locale]/layout.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Analytics } from '@vercel/analytics/react';
22
import { SpeedInsights } from '@vercel/speed-insights/next';
33
import classNames from 'classnames';
4-
import { getLocale } from 'next-intl/server';
54
import type { FC, PropsWithChildren } from 'react';
65

76
import BaseLayout from '@/layouts/Base';
@@ -15,8 +14,14 @@ import '@/styles/index.css';
1514

1615
const fontClasses = classNames(IBM_PLEX_MONO.variable, OPEN_SANS.variable);
1716

18-
const RootLayout: FC<PropsWithChildren> = async ({ children }) => {
19-
const locale = await getLocale();
17+
const RootLayout: FC<
18+
PropsWithChildren<{
19+
params: Promise<{
20+
locale: string;
21+
}>;
22+
}>
23+
> = async ({ children, params }) => {
24+
const { locale } = await params;
2025

2126
const { langDir, hrefLang } = availableLocalesMap[locale] || defaultLocale;
2227

apps/site/components/__mocks__/next-intl.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useFormatter = () => {
2727

2828
export const NextIntlClientProvider = ({ children }) => children;
2929

30-
export const createSharedPathnamesNavigation = () => ({
30+
export const createNavigation = () => ({
3131
Link: Link,
3232
redirect: redirect,
3333
usePathname: usePathname,

apps/site/hooks/react-generic/useSiteNavigation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const useSiteNavigation = () => {
3939

4040
const mapNavigationEntries = (entries: Navigation, context: Context = {}) => {
4141
const getFormattedMessage = (label: string, key: string) =>
42-
t.rich(label, context[key] || {});
42+
t.rich(label, context[key] || {}) as FormattedMessage;
4343

4444
return Object.entries(entries).map(
4545
([key, { label, link, items, target }]): [

apps/site/i18n.tsx

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { importLocale } from '@node-core/website-i18n';
22
import { getRequestConfig } from 'next-intl/server';
33

4-
import { availableLocaleCodes } from '@/next.locales.mjs';
4+
import { availableLocaleCodes, defaultLocale } from '@/next.locales.mjs';
55

66
import deepMerge from './util/deepMerge';
77

@@ -13,7 +13,7 @@ const loadLocaleDictionary = async (locale: string) => {
1313
'@node-core/website-i18n/locales/en.json'
1414
).then(f => f.default);
1515

16-
if (locale === 'en') {
16+
if (locale === defaultLocale.code) {
1717
return defaultMessages;
1818
}
1919

@@ -30,9 +30,20 @@ const loadLocaleDictionary = async (locale: string) => {
3030
};
3131

3232
// Provides `next-intl` configuration for RSC/SSR
33-
export default getRequestConfig(async ({ locale }) => ({
34-
// This is the dictionary of messages to be loaded
35-
messages: await loadLocaleDictionary(locale),
36-
// We always define the App timezone as UTC
37-
timeZone: 'Etc/UTC',
38-
}));
33+
export default getRequestConfig(async ({ requestLocale }) => {
34+
// This typically corresponds to the `[locale]` segment
35+
let locale = await requestLocale;
36+
37+
// Ensure that the incoming locale is valid
38+
if (!locale || !availableLocaleCodes.includes(locale)) {
39+
locale = defaultLocale.code;
40+
}
41+
42+
return {
43+
locale,
44+
// This is the dictionary of messages to be loaded
45+
messages: await loadLocaleDictionary(locale),
46+
// We always define the App timezone as UTC
47+
timeZone: 'Etc/UTC',
48+
};
49+
});

apps/site/navigation.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
import { createSharedPathnamesNavigation } from 'next-intl/navigation';
3+
import { createNavigation } from 'next-intl/navigation';
44

55
import { availableLocaleCodes } from './next.locales.mjs';
66

7-
export const { Link, redirect, usePathname, useRouter } =
8-
createSharedPathnamesNavigation({ locales: availableLocaleCodes });
7+
export const { Link, redirect, usePathname, useRouter } = createNavigation({
8+
locales: availableLocaleCodes,
9+
});

apps/site/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"glob": "~11.0.0",
6969
"gray-matter": "~4.0.3",
7070
"next": "~14.2.14",
71-
"next-intl": "~3.21.1",
71+
"next-intl": "~3.24.0",
7272
"next-themes": "~0.3.0",
7373
"postcss": "~8.4.47",
7474
"postcss-calc": "~10.0.2",

package-lock.json

+53-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)