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

Next-intl not working on next.js-15.0.3 version #1592

Closed
3 tasks done
rznkolds opened this issue Dec 3, 2024 · 3 comments
Closed
3 tasks done

Next-intl not working on next.js-15.0.3 version #1592

rznkolds opened this issue Dec 3, 2024 · 3 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@rznkolds
Copy link

rznkolds commented Dec 3, 2024

Description

I have constantly reviewed my code, visited various sites, looked at the documentation, but it only works without i18n routing.

This is my next.config.ts file :

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

const nextConfig: NextConfig = {

};

export default withNextIntl(nextConfig);

This is my middleware.ts file :

export { auth as middleware } from "@/utils/authorization";
import createMiddleware from 'next-intl/middleware';
import {routing} from '@/languages/i18n/routing';

export default createMiddleware(routing);

export const config = {

    matcher: ["/", "/(en|tr)/:path*"],
};

This my request.ts file in i18n folder :

import {getRequestConfig} from 'next-intl/server';
import {routing} from './routing';

export default getRequestConfig(
    async ({requestLocale}) => {

        let locale = await requestLocale;


        if (!locale || !routing.locales.includes(locale as any)) locale = routing.defaultLocale;

        return {
            locale,
            messages: (await import(`../${locale}.json`)).default
        };
    }
);

This my routing.ts file in i18n folder :

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

export const routing = defineRouting({

    locales: ['en', 'tr'],

    defaultLocale: 'en'
});

export const {Link, redirect, usePathname, useRouter, getPathname} = createNavigation(routing);

This is my layout file in src/app/[locale] folder :

import type {Metadata} from "next";
import "@/styles/global.css";
import Navigation from "@/components/common/navigation/Navigation";
import Footer from "@/components/common/footer/Footer";
import {Inter} from "next/font/google";
import React from "react";
import {NextIntlClientProvider} from 'next-intl';
import {getMessages} from 'next-intl/server';
import {notFound} from 'next/navigation';
import {routing} from '@/languages/i18n/routing';

const inter = Inter({subsets: ["latin"]});

export const metadata: Metadata = {
    title: "Create Next App",
    description: "Generated by signup next (app)",
};

export default async function RootLayout (
    {
        children,
        params
    }: {
        children: React.ReactNode;
        params: Promise<{ locale: string }>;
    }
) {

    const locale = (await params).locale

    if (!routing.locales.includes(locale as any)) notFound();

    const messages = await getMessages();

    return (
        <html lang={locale} suppressHydrationWarning>
               <body className={inter.className}>
                       <NextIntlClientProvider messages={messages}>
                               <Navigation/>
                               {
                                      children
                               }
                               <Footer/>
                       </NextIntlClientProvider>
               </body>
        </html>
    );
}

For some reason, the data changes only when the default locale section in the routing file is changed, otherwise the data does not change when the language code is specified in the url section.

Verifications

Mandatory reproduction URL

https://github.com/rznkolds/test.git

Reproduction description

Steps to reproduce:

  1. Start project
  2. Click the search bar
  3. Change language code

Expected behaviour

When the language code in the URL section changes, the page language must also change.

@rznkolds rznkolds added bug Something isn't working unconfirmed Needs triage. labels Dec 3, 2024
@amannn
Copy link
Owner

amannn commented Dec 4, 2024

Your middleware is in the wrong folder. You need to move it to src if you use that folder (see the docs).

@rznkolds
Copy link
Author

rznkolds commented Dec 5, 2024

@amannn Isn't there a way to define a path for this because as far as I know, the middleware file in next.js projects is generally not located under the src folder ?

The middleware file is usually defined under the root directory.

@amannn
Copy link
Owner

amannn commented Dec 6, 2024

Next.js defines the convention on where a middleware needs to be put. And currently that contains that if you have a src folder, you need to put the middleware there.

I'm closing this since this is not actionable for next-intl.

@amannn amannn closed this as completed Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants