Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I recently added the package and got this error. I have followed all the steps as far as I know.

I use Next.js with the next-i18next package which usually initialises itself automatically.

https://github.com/m2vi/downloader

like image 676
m2v Avatar asked Jun 08 '21 21:06

m2v


People also ask

What is i18next in react?

Based on the React i18n framework, react-i18next is another popular internationalization library which uses components to render or re-render the translated content of your application once users request a change of language.

Can I use react-i18next in Nextjs?

Next. js has supported i18n since v10. 0.0, it allows us to set the default language, the current language in use, and the supported languages. To set locales in a Next.


1 Answers

From the next-i18next docs:

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

Meaning you'll need to add serverSideTranslation to the pages that need translations.


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;

Then further down in your Main component you can access the documentation translation using:

t('pages.documentation')
like image 190
juliomalves Avatar answered Sep 17 '22 15:09

juliomalves