【发布时间】:2015-10-23 04:23:35
【问题描述】:
我正在尝试为i18n-node-2 创建一个 Handlebars 助手,以便我可以直接从视图中使用本地化字符串,但是首先使用 Express 助手注册 i18n,然后我无法获得我可以在 helper 中使用 i18n。
相关代码:
var i18n = require('i18n-2');
向 Express 注册 i18n:
i18n.expressBind(app, {
locales: ['en', 'de'],
cookieName: 'locale',
extension: ".json"
});
创建我的助手:
hbs.registerHelper('__', function() {
// What I would *like* to do, but the 'i18n' instance here is the wrong one
return i18n.__.apply(i18n, arguments);
});
基本上,在助手内部,我需要由i18n.expressBind() 创建的i18n 实例,它调用i18n.init()。除了修改源代码返回这个实例,有没有其他方法可以获取?
【问题讨论】:
标签: node.js express handlebars.js