摩卡testingi18n TypeError:无法读取未定义的属性'text50'

我正在使用摩卡testing框架来testing我的应用程序和翻译我使用从mashpie i18n。
在我的validation.js文件中,我需要i18​​n模块并使用i18n .__函数

console.log(i18n.__('text50'));

在我的testing文件validation.test.js我需要validation.js进行testing。 然后我用摩卡运行testing,因为我得到的结果。

 Running "mochaTest:test" (mochaTest) task >> Mocha exploded! >> TypeError: Cannot read property 'text50' of undefined >> at translate (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:355:23) >> at Object.i18nTranslate [as __] (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:96:11) >> at Object.<anonymous> (/Volumes/Develop/townspeech/server/libs/validation.js:24:18) >> at Module._compile (module.js:456:26) >> at Object.Module._extensions..js (module.js:474:10) >> at Module.load (module.js:356:32) >> at Function.Module._load (module.js:312:12) >> at Module.require (module.js:364:17) >> at require (module.js:380:17) >> at Object.<anonymous> (/Volumes/Develop/townspeech/server/controllers/new_password.js:10:18) Warning: Task "mochaTest:test" failed. Used --force, continuing. 

但是,当我尝试

 node validation.js 

作为输出我有文本,而不是错误。 为什么当我做testing时,我得到了错误,像往常一样执行不?

这是一个古老的问题,但为了别人的利益,这里是解决scheme,为我工作:

很可能它是locale目录的位置。 检查在i18n.configure中configuration的locate目录的位置是否相对。

当你执行节点和执行摩卡testing时,你从不同的位置运行,因此i18n无法find本地文件夹。