Skip to content

Commit

Permalink
fix: resolve several next-intl deprecation warnings (#1336)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Jan 3, 2025
1 parent d678ab1 commit ae09b4d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
19 changes: 15 additions & 4 deletions ui/i18n.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Text } from "@/libs/patternfly/react-core";
import { getRequestConfig } from "next-intl/server";
import { IntlConfig } from "use-intl";
import { routing } from './i18n/routing';

export const defaultTranslationValues: IntlConfig["defaultTranslationValues"] =
{
Expand All @@ -12,7 +13,17 @@ export const defaultTranslationValues: IntlConfig["defaultTranslationValues"] =
text: (text) => <Text>{text}</Text>,
};

export default getRequestConfig(async ({ locale }) => ({
messages: (await import(`./messages/${locale}.json`)).default,
defaultTranslationValues,
}));
export default getRequestConfig(async ({ requestLocale }) => {
let locale = await requestLocale;

// Ensure that the incoming locale is valid
if (!locale || !routing.locales.includes(locale as any)) {
locale = routing.defaultLocale;
}

return ({
messages: (await import(`./messages/${locale}.json`)).default,
defaultTranslationValues,
locale,
});
});
18 changes: 11 additions & 7 deletions ui/i18n/request.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
import { routing } from "@/i18n/routing";

export default getRequestConfig(async ({ locale }) => {
// Validate that the incoming `locale` parameter is valid
if (!routing.locales.includes(locale as any)) notFound();
export default getRequestConfig(async ({ requestLocale }) => {
let locale = await requestLocale;

return {
messages: (await import(`../../messages/${locale}.json`)).default,
};
// Ensure that the incoming locale is valid
if (!locale || !routing.locales.includes(locale as any)) {
locale = routing.defaultLocale;
}

return {
messages: (await import(`../../messages/${locale}.json`)).default,
locale,
};
});
14 changes: 11 additions & 3 deletions ui/i18n/routing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineRouting } from "next-intl/routing";
import { createSharedPathnamesNavigation } from "next-intl/navigation";
import { createNavigation } from "next-intl/navigation";

export const locales = ["en"] as const;

Expand All @@ -14,5 +14,13 @@ export const routing = defineRouting({

// Lightweight wrappers around Next.js' navigation APIs
// that will consider the routing configuration
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation(routing);
let nav = createNavigation(routing);

export const { Link, redirect, usePathname, useRouter } = {
Link: nav.Link,
redirect: (path: string) => {
nav.redirect({ href: path, locale: "en" });
},
usePathname: nav.usePathname,
useRouter: nav.useRouter,
};

0 comments on commit ae09b4d

Please sign in to comment.