Can't find a way to make it work, error with 'options' or 'getFixedT'
See original GitHub issueHi,
I’m trying to configure i18next with my React project and I can’t make it work at all…
Whatever I try, I get either this :
TypeError: Cannot read property 'options' of undefined
at new Translate (/Users/ank49/Documents/React Projects/Portfolio React i18n/node_modules/react-i18next/dist/commonjs/translate.js:65:32)
or this :
TypeError: Cannot read property 'getFixedT' of undefined
at Translate.componentWillMount (/Users/ank49/Documents/React Projects/Portfolio React i18n/node_modules/react-i18next/dist/commonjs/translate.js:84:46)
I initialized my i18n with the React and WebPack 2 example as the following :
import i18n from 'i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
i18n.use(LanguageDetector)
.init({
loadPath: 'locales/{{lng}}/{{ns}}.json',
preload: ['en-US', 'fr-FR'],
fallbackLng: 'fr-FR',
// wait: true, // globally set to wait for loaded translations in translate hoc
// have a common namespace used around the full app
ns: ['common',
'navbar',
'footer',
'header',
'about',
'experience',
'skills',
'p_app',
'p_web',
'cv',
'social',
'events',
'contact',
'support'],
defaultNS: 'common',
debug: true,
// cache: {
// enabled: true
// },
interpolation: {
escapeValue: false, // not needed for react!!
},
wait: true,
})
export default i18n
and my component I’m trying to translate is as follow :
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import withStyles from 'isomorphic-style-loader/lib/withStyles'
import Typist from 'react-typist'
import { translate } from 'react-i18next'
import { Parenthesis } from '../../components'
import style from './header.scss'
class Header extends Component {
static propTypes = {
t: PropTypes.func.isRequired,
}
render() {
const { t } = this.props
return (
<div>
<section className="header">
<div className="header_content">
<div className="header_content_inner">
<h1 id="homeTextHead">{t('header.title')}</h1>
<hr className="bg_dark"/>
<br/>
<Typist avgTypingDelay={90} className="typed_text">
{t('header.name')}
<br/>
<Parenthesis>{t('header.pseudo')}</Parenthesis>
<br/>
<br/>
{t('header.description')}
</Typist>
</div>
</div>
</section>
</div>
)
}
}
export default withStyles(style)(translate(['header'], { wait: true })(Header))
I also tried with the decorator but I got the same issues…
@translate(['header'])
class Header extends Component {
...
}
export default withStyles(style)(Header)
Any help is welcome, thanks in advance guys !
Issue Analytics
- State:
- Created 6 years ago
- Comments:36 (18 by maintainers)
Top Results From Across the Web
i18next + React + Webpack - getFixedT is not a function
My initial problem was loading the locales. The i18n couldn't find the files after the build, because the webpack doesn't recognize the i18n-xhr ......
Read more >API - i18next documentation
init. i18next.init(options, callback) // -> returns a Promise. The default export of the i18next module is an i18next instance ready to be initialized...
Read more >i18next + React + Webpack - getFixedT is not a function-Reactjs
I'm Trying to Inject An NPM package As A Plugin on A Next. · How do i pass a variable to multiple layers...
Read more >How to use the i18next.isInitialized function in i18next - Snyk
isInitialized function in i18next. To help you get started, we've selected a few i18next examples, based on popular ways it is used in...
Read more >next-i18next - npm
The easiest way to translate your NextJs apps. ... How does it work? ... First, create a next-i18next.config.js file in the root of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

If anyone is having the error
XMLHttpRequest is not definedusinggatsby build, just install the packagenpm i -S xmlhttprequestand then in the top ofgatsby-node.jsfile add:And now the
buildcommand works as expected, you can verify it by runninggatsby serve.I’ve read that, but it’s quite cumbersome. The closest I got is detailed below. I had to fuse all translation files into one per language otherwise it was beyond my webpack skills, but that defeats the point of loading just the relevant component’s translations by XHR. Besides, even with this I still have warnings during
gatsby build. I think all these implementation details should be part of the package.