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

not-found.tsx is not translated #67

Open
brunoscopelliti opened this issue Jul 29, 2023 · 3 comments
Open

not-found.tsx is not translated #67

brunoscopelliti opened this issue Jul 29, 2023 · 3 comments

Comments

@brunoscopelliti
Copy link

brunoscopelliti commented Jul 29, 2023

What version of this package are you using?

next: 13.4.12
next-translate: 2.5.2
next-translate-plugin: 2.5.2

Node.js v20.5.0

What happened?

In the not-found.tsx page we see the label key, instead of the actual label content.
Attaching a repro:

repro.zip

What did you expect to happen?

See the translated label.

@aralroca
Copy link
Owner

aralroca commented Jul 31, 2023

@brunoscopelliti I replaced this file:

import getT from "next-translate/getT";

const Page404 = async ({ searchParams }: any) => {
  const t = await getT(searchParams?.lang as string, ["common"]);
  return (
    <div>Test: {t("label_1")}</div>
  );
};

export default Page404;

to:

import createTranslation from "next-translate/useTranslation";

const Page404 = async () => {
  const { t } = createTranslation("common");

  return (
    <div>Test: {t("label_1")}</div>
  );
};

export default Page404;

And now the translation works fine.

The problem is that searchParams is undefined in not-found.tsx file, so this is why getT is not returing the translation, because the lang is missing.

And related with this issue aralroca/next-translate#1118 is better to rename useTranslation to createTranslation or another name because useTranslation is not a hook now and can be conflictive with async components. We are going to do the change in future releases.

@brunoscopelliti
Copy link
Author

@aralroca Thank you for your advices.
Ok, that works, but how I am supposed to render any other language than the default one?
Also, since useTranslation is not an hook any chance in a future version we could have the option to import from something different than "next-translate/useTranslation"?

@aralroca
Copy link
Owner

aralroca commented Aug 4, 2023

@aralroca Thank you for your advices. Ok, that works, but how I am supposed to render any other language than the default one?

It's using the language of the dynamic route /[lang], if you need another one you can use getT, but passing the correct language instead of undefined.

Also, since useTranslation is not an hook any chance in a future version we could have the option to import from something different than "next-translate/useTranslation"?

Yes, this is the idea. Something like "next-translate/createTranslation" or another name (not sure the final name yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants