javascript - use i18n-node in server-side express application -
i can't figure out how should utilize i18n-node module within application.
within views, static texts, it's easy, works but...
here problem :
sometimes have set error messages or else, e.g :
req.flash('message', __('unknown user %s', login)); then i'll have send message views, e.g :
res.render('myview', {message: req.flash('message')}); but first, message "unknown user %s" set in default language json file, , if set "unknown user %s": "something in client language" in client language json file, still display "unknown user myuserlogin".
does have working illustration share ?
edit: , because, there variable in translated string, can't :
res.render('myview', {message: __(req.flash('message'))}); because set "unknown user myuserlogin" in client language json file, instead of "unknown user %s"...
i know question kind of old, ran same issue , found solution.
since using flash method req object, should utilize __ method available in same object:
req.flash('message', req.__('unknown user %s', login)); this way it's gonna translated using current locale of request.
javascript node.js express internationalization i18n-node
No comments:
Post a Comment