react-i18next:: 你需要使用 initReactI18next 传入一个 i18next 实例 [英] react-i18next:: You will need to pass in an i18next instance by using initReactI18next

查看:221
本文介绍了react-i18next:: 你需要使用 initReactI18next 传入一个 i18next 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我最近添加了包并收到此错误.据我所知,我已按照所有步骤进行操作.

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 添加到 getStaticPropsgetServerSideProps(取决于您的情况).

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

意味着您需要将 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 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆