import i18n from 'i18n-2'
export class Navbar extends Component {
constructor(props) {
super(props)
}
render() {
return (
the <li><indexlink to="/" activeclassname="{styles.active}">{__('Home')}</indexlink></li>
)
}
i18n.expressBind(app, {
locales: ['EN', 'en'],
directory: __dirname + '/locales',
fallbacks: true
extension: '.js',
defaultLocale: 'EN',
is 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();
});
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);
...
},
...
}
Find more questions by tags Express.jsNode.jsReact
and when ?lang=en translates without problems, but in the browser error Uncaught ReferenceError: __ is not defined
can advise normal react library?
to be able to cook to hang - audra.Lubowitz commented on June 8th 19 at 17:10
Let's see what there is and choose what you like. - jackeline.OConner commented on June 8th 19 at 17:13