Answer the question
In order to leave comments, you need to log in
How to fix Uncaught ReferenceError: __ is not defined?
Please help fix!!!
I'm trying to connect i18n-2 translation
import i18n from 'i18n-2'
export class Navbar extends Component {
constructor(props) {
super(props)
}
render() {
return (
<li><IndexLink to="/" activeClassName={styles.active}>{__('Home')}</IndexLink></li>
)
}
i18n.expressBind(app, {
locales: ['ru', 'en'],
directory: __dirname + '/locales',
fallbacks: true,
extension: '.js',
defaultLocale: 'ru',
cookieName: 'lang',
register: global,
api: {
'__': 't',
'__n': 'tn'
}
});
app.use(function(req, res, next) {
if(req.query.lang) {
req.i18n.setLocaleFromQuery();
res.cookie('lang', req.i18n.getLocale());
} else {
req.i18n.setLocaleFromCookie();
}
next();
});
Answer the question
In order to leave comments, you need to log in
The i18n-2 library cannot be used in React, it is only for Nody.
Look at the library code .
Here is a piece of code that is responsible for reading files with translations:
var i18n = module.exports = function (opt) {
...
if (opt.locales && opt.locales.forEach) {
this.locales = {};
opt.locales.forEach(function (locale) {
self.readFile(locale);
});
}
...
}
i18n.prototype = {
...
readFile: function (locale) {
var file = this.locateFile(locale);
...
try {
var localeFile = fs.readFileSync(file);
...
},
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question