m2v*_*m2v 6 i18next reactjs next.js
react-i18next:: 你需要使用 initReactI18next 传入一个 i18next 实例
我最近添加了该包并出现此错误。据我所知,我已按照所有步骤进行操作。
我将 Next.js 与next-i18next
通常自动初始化的包一起使用。
jul*_*ves 29
然后我们在页面级组件中添加或(取决于您的情况
serverSideTranslation
)getStaticProps
。getServerSideProps
这意味着您需要添加serverSideTranslation
到需要翻译的页面。
例如在您的pages/d/[tab]/index
文件中:
import Head from 'next/head';
import { Input } from '../../../components/Input';
import YouTube from '../../../components/youtube/Main';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
const index = () => {
return (
<>
<Head>
<title>YouTube</title>
</Head>
<YouTube />
</>
);
};
export const getServerSideProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale, ['common']))
}
});
export default index;
Run Code Online (Sandbox Code Playgroud)
然后,在您的Main
组件中,您可以documentation
使用以下命令访问翻译:
t('pages.documentation')
Run Code Online (Sandbox Code Playgroud)
pa4*_*080 22
就我而言,问题是由 VSC 导入建议造成的一个愚蠢的拼写错误,并且首先是我的粗心。
所以而不是:
import { useTranslation } from "next-i18next";
Run Code Online (Sandbox Code Playgroud)
...进口声明是:
import { useTranslation } from "react-i18next";
Run Code Online (Sandbox Code Playgroud)
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'de', 'fr'],
},
react: { useSuspense: false },//this line
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2453 次 |
最近记录: |