node.js - Jquery i18next translation issue -


i developing nodejs app.

here how initialize i18next in app.js:

var i18n = require('i18next'); i18n.init({ savemissing: true, debug: true }); 

here js code:

...     // display strength based on score     switch (strength.score) {     case 0:         $('#strength-meter').removeclass()         $('#strength-meter').addclass('progress-bar progress-bar-danger')         $('.progress .progress-bar').css('width', '25%')         return 'very weak'         break; ... 

i have tried using "return i18n.t('app.phlastname');". "uncaught referenceerror: i18n not defined." error

what doing wrong? in advance.

update

i changed code works on clientside. included i18n lib in page. , updated javascript/jquery code this:

$.i18n.init({   debug: true   }, function(t) {      return t("app.lblname"); }); 

so don't seem above mentioned error, not getting text.

when not using translation this: want this

getting this

i able find answer question.

the problem was, returning translated string inside function , hence outside of scope intended displayed.

so initialized separately (say in document.ready)

$.i18n.init({         usecookie: false,         debug: true,         resgetpath: 'locales/__lng__/translation.json'     }); 

and used separately,

return $.i18n.t("app.lblname"); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -