【发布时间】:2017-12-24 14:22:35
【问题描述】:
我想在我的 Node.js 应用程序中使用 ES6 模板字符串作为翻译模板。
我有一个 JSON 文件 en_GB.json 像这样:
{
"app.template": "This is ${foo} I ${bar}",
"app.foo": "bar"
}
在节点中我这样做:
const translations = require('./en_GB.json')
const foo = 'what'
const bar = 'want'
console.log(translations['app.template']) // Outputs This is ${foo} I ${bar}
我想要输出的是“这就是我想要的”
不使用辅助函数可以吗?
【问题讨论】:
标签: javascript json ecmascript-6 template-strings