问题描述
react-i18next:: 你需要使用 initReactI18next 传入一个 i18next 实例
我最近添加了包并收到此错误.据我所知,我已按照所有步骤进行操作.
I recently added the package and got this error. I have followed all the steps as far as I know.
我将 Next.js 与 next-i18next
包一起使用,该包通常会自动初始化.
I use Next.js with the next-i18next
package which usually initialises itself automatically.
https://github.com/m2vi/downloader
推荐答案
来自 next-i18next
文档:
From the next-i18next
docs:
然后我们在页面级组件中将 serverSideTranslation
添加到 getStaticProps
或 getServerSideProps
(取决于您的情况).
意味着您需要将 serverSideTranslation
添加到需要翻译的页面.
Meaning you'll need to add serverSideTranslation
to the pages that need translations.
例如在您的 pages/d/[tab]/index
文件中:
For example in your pages/d/[tab]/index
file:
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;
然后在 Main
组件的下方,您可以使用以下方法访问 documentation
翻译:
Then further down in your Main
component you can access the documentation
translation using:
t('pages.documentation')
这篇关于react-i18next:: 你需要使用 initReactI18next 传入一个 i18next 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!