Code Monkey home page Code Monkey logo

Comments (3)

adrai avatar adrai commented on June 14, 2024

You're talking about app routing and not page routing, so this is not related to next-i18next...
but yes, with this example you need to pass down the lng...
alternatively there is https://github.com/i18next/next-app-dir-i18next-no-locale-path-example but that is also not optimal...
If you have a better idea, feel free to fork this example and modify it to your needs

from react-i18next.

adrai avatar adrai commented on June 14, 2024

Just added a hint here: i18next/next-app-dir-i18next-example@17ba4b8

from react-i18next.

RowinVanAmsterdam avatar RowinVanAmsterdam commented on June 14, 2024

Thank you for your response. Just to clarify, my issue, or the message where I sought advice, was indeed related to react-i18next and app router, not specifically to next-i18next or page routing. From my understanding I didn't name it next-i18next nor page router, right?

Following your hint, I've identified where the fault was in my "Expected behavior" example. I overlooked removing the async part from the client function, causing Next.js to interpret it as a server component. For anyone encountering a similar issue, the corrected code should work as expected now:

'use client'

import { useTranslation } from "@/i18n/client";
import { useParams } from "next/navigation";

export default function ClientComponent() {
    const params = useParams();
    const { t } = useTranslation(params.locale as string);

    return (
            <div>
                <h1>Client Component</h1>
                <h1>translation: {t("title")}</h1>
            </div>
    );
}

Thank you for your guidance, and I hope this clarification helps others facing similar challenges.

from react-i18next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.