Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve several next-intl deprecation warnings #1336

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
Comment on lines +19 to +26
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect function requires the locale on each use now. This is a cheat to use the default since we're only supporting en at the moment.