react-i18next:: 您需要使用 initReactI18next 传入一个 i18next 实例

react-i18next:: You will need to pass in an i18next instance by using initReactI18next

react-i18next:: You will need to pass in an i18next instance by using initReactI18next

我最近添加了包并遇到了这个错误。据我所知,我已按照所有步骤进行操作。

我使用 Next.js 和 next-i18next 包,它通常会自动初始化。

https://github.com/m2vi/downloader

来自next-i18next docs

Then we add serverSideTranslation to getStaticProps or getServerSideProps (depending on your case) in our page-level components.

意味着您需要将 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;

然后在 Main 组件的更下方,您可以使用以下方式访问 documentation 翻译:

t('pages.documentation')

接下来更新-i18next.config.js

module.exports = {
    i18n: {
        defaultLocale: 'en',
        locales: ['en', 'de', 'fr'],
    },
    react: { useSuspense: false },//this line
};