useTranslation Hook not showing autocomplete for Next.js (TS) #2029
-
When importing here is my /**
* If you want to enable locale keys typechecking and enhance IDE experience.
*
* Requires `resolveJsonModule:true` in your tsconfig.json.
*
* @link https://www.i18next.com/overview/typescript
*/
import "i18next";
import type common from "../../public/locales/en/common.json";
import type main from "../../public/locales/en/main.json";
import type index from "../../public/locales/en/index.json";
import type login from "../../public/locales/en/login.json";
import type signup from "../../public/locales/en/signup.json";
interface I18nNamespaces {
common: typeof common;
main: typeof main;
index: typeof index;
login: typeof login;
signup: typeof signup;
}
declare module "i18next" {
interface CustomTypeOptions {
defaultNS: "common";
resources: I18nNamespaces;
}
} and here is my import { useTranslation } from "next-i18next"; // works but no autocomplete
// import { useTranslation } from "react-i18next"; // does not show content instead ( e.g common:login) but autocomplete exist
type PageProps = {};
export default function Home({}: InferGetServerSidePropsType<GetServerSideProps>) {
const { t } = useTranslation(["common", "index"]);
return (
<div>
<TitleText>{strings.app_name}</TitleText>
<ThemeSwitcher variant="multiple" />
<Link href={"/login"}>
<u>{t("common:login")}</u>
</Link>
<br />
<Link href={"/signup"}>
<u>{t("common:create-an-account")}</u>
</Link>
</div>
);
}
export const getServerSideProps: GetServerSideProps<PageProps> = async ({ locale }) => {
return {
props: {
...(await serverSideTranslations(locale ?? "en", ["common", "index"])),
},
};
}; Please any help or suggestion will be appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Upcoming release only (v13.0.0). In the meantime import "react-i18next"; // (in the future 'i18next')
import type common from "../../public/locales/en/common.json";
import type main from "../../public/locales/en/main.json";
import type index from "../../public/locales/en/index.json";
import type login from "../../public/locales/en/login.json";
import type signup from "../../public/locales/en/signup.json";
interface I18nNamespaces {
common: typeof common;
main: typeof main;
index: typeof index;
login: typeof login;
signup: typeof signup;
}
// (was 'i18next')
declare module "react-i18next" {
interface CustomTypeOptions {
defaultNS: "common";
resources: I18nNamespaces;
}
} When 13.0.0 is out, you'll have to change once more :) See UPGRADING. Let me know if it helped |
Beta Was this translation helpful? Give feedback.
Upcoming release only (v13.0.0). In the meantime