Skip to content

Commit

Permalink
Revert "chore: Upgrade next-intl to 3.24, migrate deprecated APIs" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd authored Nov 14, 2024
1 parent 24925de commit fa6fbd9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 90 deletions.
6 changes: 3 additions & 3 deletions apps/site/app/[locale]/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setContext, setTags } from '@sentry/nextjs';
import { notFound, redirect } from 'next/navigation';
import { setRequestLocale } from 'next-intl/server';
import { unstable_setRequestLocale } from 'next-intl/server';
import type { FC } from 'react';

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

if (!availableLocaleCodes.includes(locale)) {
// Forces the current locale to be the Default Locale
setRequestLocale(defaultLocale.code);
unstable_setRequestLocale(defaultLocale.code);

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

// Configures the current Locale to be the given Locale of the Request
setRequestLocale(locale);
unstable_setRequestLocale(locale);

// Gets the current full pathname for a given path
const pathname = dynamicRouter.getPathname(path);
Expand Down
11 changes: 3 additions & 8 deletions apps/site/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/next';
import classNames from 'classnames';
import { getLocale } from 'next-intl/server';
import type { FC, PropsWithChildren } from 'react';

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

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

const RootLayout: FC<
PropsWithChildren<{
params: Promise<{
locale: string;
}>;
}>
> = async ({ children, params }) => {
const { locale } = await params;
const RootLayout: FC<PropsWithChildren> = async ({ children }) => {
const locale = await getLocale();

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

Expand Down
2 changes: 1 addition & 1 deletion apps/site/components/__mocks__/next-intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useFormatter = () => {

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

export const createNavigation = () => ({
export const createSharedPathnamesNavigation = () => ({
Link: Link,
redirect: redirect,
usePathname: usePathname,
Expand Down
2 changes: 1 addition & 1 deletion apps/site/hooks/react-generic/useSiteNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const useSiteNavigation = () => {

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

return Object.entries(entries).map(
([key, { label, link, items, target }]): [
Expand Down
27 changes: 8 additions & 19 deletions apps/site/i18n.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { importLocale } from '@node-core/website-i18n';
import { getRequestConfig } from 'next-intl/server';

import { availableLocaleCodes, defaultLocale } from '@/next.locales.mjs';
import { availableLocaleCodes } from '@/next.locales.mjs';

import deepMerge from './util/deepMerge';

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

if (locale === defaultLocale.code) {
if (locale === 'en') {
return defaultMessages;
}

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

// Provides `next-intl` configuration for RSC/SSR
export default getRequestConfig(async ({ requestLocale }) => {
// This typically corresponds to the `[locale]` segment
let locale = await requestLocale;

// Ensure that the incoming locale is valid
if (!locale || !availableLocaleCodes.includes(locale)) {
locale = defaultLocale.code;
}

return {
locale,
// This is the dictionary of messages to be loaded
messages: await loadLocaleDictionary(locale),
// We always define the App timezone as UTC
timeZone: 'Etc/UTC',
};
});
export default getRequestConfig(async ({ locale }) => ({
// This is the dictionary of messages to be loaded
messages: await loadLocaleDictionary(locale),
// We always define the App timezone as UTC
timeZone: 'Etc/UTC',
}));
7 changes: 3 additions & 4 deletions apps/site/navigation.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

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

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

export const { Link, redirect, usePathname, useRouter } = createNavigation({
locales: availableLocaleCodes,
});
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales: availableLocaleCodes });
2 changes: 1 addition & 1 deletion apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"glob": "~11.0.0",
"gray-matter": "~4.0.3",
"next": "~14.2.14",
"next-intl": "~3.24.0",
"next-intl": "~3.21.1",
"next-themes": "~0.3.0",
"postcss": "~8.4.47",
"postcss-calc": "~10.0.2",
Expand Down
105 changes: 52 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa6fbd9

Please sign in to comment.