Arslan Tariq
Arslan Tariq

Reputation: 2538

i18next is undefined in react app

I have just started using i18next package on my react app but I'm having a problem. I did 'yarn add [email protected] --save' to install the package. And then in my component I did this:

import i18next from 'i18next'
// other imports...

// defining class
constructor(props){
  super(props)

  console.log(i18next.t('Wähle einen Titel für deinen Ratgeber'))
}

And in render method I'm doing this

<Explainer header={i18next.t('Was macht ein gutes Thema aus?')}>
   <GoodTitleExplainer/>
</Explainer>

So, on console, I am getting undefined and an error The prop header is marked as required in Explainer, but its value is undefined.

I have got it working in another project but I don't know what's the problem here. Help please.

Upvotes: 1

Views: 1101

Answers (1)

jamuhl
jamuhl

Reputation: 4498

Did you init the i18next instance? https://www.i18next.com/getting-started.html#basic-sample

Further for using with react i highly recommend using react-i18next: https://react.i18next.com makes loading translations and usage a lot easier

Upvotes: 1

Related Questions