Closed ricoxor closed 1 year ago
useTranslation()
should be used only in components (it's a react hook), and not at the top of the page.
btw. make sure you import useTranslation from next-i18next and NOT from react-i18next. https://github.com/i18next/next-i18next#usetranslation
Hello, I'm using useTranslation() on top of my component. Here is the code
import Image from "next/image";
import ReactPlayer from "react-player";
import Link from "next/link";
import React from "react";
import { useState } from "react";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
const Details = ({ data }) => {
const { t, ready } = useTranslation("common");
console.log("Ready : " + ready);
....
}
export async function getStaticPaths() {
const { data } = await api.get("/sites");
const sites = data.data;
const paths = sites.map((site) => ({
params: { name: site.attributes.slug },
}));
return { paths, fallback: true };
}
export async function getStaticProps({ locale, params }) {
const currentLocale = locale;
const { name } = params;
....
return {
props: {
...(await serverSideTranslations(locale, ["common"])),
data: pageData,
},
};
}
What's wrong @adrai ? When I build when /pages/game/[game].jsx come the first log is always a ready to false.
Here is my _app.js
import { Layout } from "@/components/layout";
...
import { appWithTranslation } from 'next-i18next';
import Head from "next/head";
import { useRouter } from 'next/router';
function App({ Component, pageProps }) {
const router = useRouter();
return (
<Layout>
<Head>
....
</Head>
<Component {...pageProps} />
</Layout>
);
}
export default appWithTranslation(App);
Please create a minimal reproducible example repo.
Please create a minimal reproducible example repo.
this is only occurring because you've set fallback to true:
So for a non-existing route the serverSideTranslations function is never executed.
Thank you @adrai
Hello I have an react-i18next error when I build my project.
I'm using next-i18next & next 13
Here is my dependencies :
The issue occur on my page /src/pages/game/[name].jsx On the top of the page I added this :
Here is the console logs when I build :
Eveything is working in dev.
How can I fix this issue please? Thank you in advance