Skip to content

Commit

Permalink
chore: next-intl upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSinclair committed Jan 13, 2025
1 parent a949426 commit 0720150
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 95 deletions.
2 changes: 1 addition & 1 deletion examples/with-next-app-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
"next": "^15.1.4",
"next-intl": "^3.19.1",
"next-intl": "^3.26.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"viem": "2.21.55",
Expand Down
28 changes: 16 additions & 12 deletions examples/with-next-app-i18n/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, setRequestLocale } from 'next-intl/server';
import type { Locale } from '@rainbow-me/rainbowkit';
import { Providers } from './providers';

Expand All @@ -7,23 +7,27 @@ export function generateStaticParams() {
}

// Dynamic metadata with locale
export async function generateMetadata(
{ params: { locale } }: { params: { locale: Locale } }
) {
export async function generateMetadata(props: { params: Promise<{ locale: Locale }> }) {
const params = await props.params;
const { locale } = params;

const t = await getTranslations({ locale, namespace: 'Metadata' });
return {
title: t('title')
};
}

export default function LocaleLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: { locale: Locale };
}) {
unstable_setRequestLocale(locale);
export default async function LocaleLayout(
props: {
children: React.ReactNode;
params: Promise<{ locale: Locale }>;
}
) {
const { children } = props;
const params = await props.params;
const { locale } = params;

setRequestLocale(locale);

return (
<html lang={locale}>
Expand Down
13 changes: 0 additions & 13 deletions examples/with-next-app-i18n/src/i18n.ts

This file was deleted.

17 changes: 17 additions & 0 deletions examples/with-next-app-i18n/src/i18n/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getRequestConfig } from 'next-intl/server';
import { routing } from './routing';

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 || !routing.locales.includes(locale as any)) {
locale = routing.defaultLocale;
}

return {
locale,
messages: (await import(`../../messages/${locale}.json`)).default
};
});
8 changes: 8 additions & 0 deletions examples/with-next-app-i18n/src/i18n/routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {defineRouting} from 'next-intl/routing';

export const routing = defineRouting({
// A list of all locales that are supported
locales: ['en-US', 'zh-CN'],
// Used when no locale matches
defaultLocale: 'en-US',
});
12 changes: 4 additions & 8 deletions examples/with-next-app-i18n/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import createMiddleware from 'next-intl/middleware';

export default createMiddleware({
// A list of all locales that are supported
locales: ['en-US', 'zh-CN'],
// Used when no locale matches
defaultLocale: 'en-US'
});

import {routing} from './i18n/routing';

export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(de|en)/:path*']
};

export default createMiddleware(routing);
Loading

0 comments on commit 0720150

Please sign in to comment.