Closed Butonix closed 6 years ago
Hi,
Please make your next messages a bit clearer :)
You're using i18n in a express (node.js, server-side) and expect it to be available in a react (browser, client-side) ? This is not how it works. Either use templates, or a translation api to use i18n-node-2
I have combined react and express, the fact is that he translates the phrase, but gives an error in the console. Tell me how to use api? can show an example of visual Thanks
Documentation is available in the README file : https://github.com/jeresig/i18n-node-2
Again, you might be declaring i18n in express and using __
from React on client side. You can not « combine react and express ».
I'm closing this as this is not related with i18n
hi file
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> ) }
app.js
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(); });