This is a Next.js project bootstrapped with create-next-app
.
module.exports = {
i18n: {
defaultLocale: "en",
locales: ["en", "bn", "ar", "hi"],
},
};
/** @type {import('next').NextConfig} */
const { i18n } = require("./next-i18next.config");
const nextConfig = {
reactStrictMode: true,
i18n,
};
module.exports = nextConfig;
export default appWithTranslation(MyApp);
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
export default function Home() {
const { t } = useTranslation("home");
<h1>{t("our_universe")}</h1>;
}
// Eta na use korle locales json pabena
export const getStaticProps = async ({ locale }) => {
return {
props: {
...(await serverSideTranslations(locale, ["home"])),
},
};
};
// Using Link to change locale
{
locales.map((loc) => (
<Link key={loc} href={"/"} locale={loc}>
<button>{loc}</button>
</Link>
));
}
// Using useRouter {push} to change locale
const handleClick = (e) => {
push("/", undefined, { locale: "ar" });
};
<button onClick={handleClick}>PUSH ARABIC LANG</button>;