Skip to content

Resolve deprecated i18n request configuration #367

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

Merged
merged 1 commit into from
Feb 28, 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: 19 additions & 0 deletions i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Can be imported from a shared config
export const locales = [
'ar',
'en',
'en-GB',
'es',
'ewe-BJ',
'fon-BJ',
'fr',
'hau-NG',
'yor-NG',
'ja',
'ko',
'vi',
'zh-CN',
'zh-TW'
] as const;

export const defaultLocale = 'en';
23 changes: 2 additions & 21 deletions src/i18n.ts → i18n/request.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import { notFound } from 'next/navigation';
import { getRequestConfig } from 'next-intl/server';

// Can be imported from a shared config
export const locales = [
'ar',
'en',
'en-GB',
'es',
'ewe-BJ',
'fon-BJ',
'fr',
'hau-NG',
'yor-NG',
'ja',
'ko',
'vi',
'zh-CN',
'zh-TW'
] as const;

export const defaultLocale = 'en';
import { locales } from './i18n';

export default getRequestConfig(async ({ locale }) => {
// Validate that the incoming `locale` parameter is valid
Expand All @@ -28,4 +9,4 @@ export default getRequestConfig(async ({ locale }) => {
return {
messages: (await import(`../messages/${locale}.json`)).default,
};
});
});
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createNextIntlPlugin from 'next-intl/plugin';
import { withSentryConfig } from "@sentry/nextjs";

const withNextIntl = createNextIntlPlugin();
const withNextIntl = createNextIntlPlugin('./i18n/request.ts');

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextIntlClientProvider, useMessages } from 'next-intl';
import { setRequestLocale } from 'next-intl/server';
import { Lato } from 'next/font/google';
import { locales } from '@/i18n';
import { locales } from '../../../i18n/i18n';
import { Providers } from '../providers';
import Navbar from '@/components/shared/navbar/Navbar';
import logger from '../../../logger.config.mjs';
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createMiddleware from 'next-intl/middleware';
import { locales, defaultLocale } from './i18n';
import { locales, defaultLocale } from '../i18n/i18n';
import { localePrefix } from './navigation';

export default createMiddleware({
Expand Down
2 changes: 1 addition & 1 deletion src/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSharedPathnamesNavigation } from 'next-intl/navigation';
import { locales } from './i18n';
import { locales } from '../i18n/i18n';

export const localePrefix = 'as-needed';

Expand Down