l20n:服务器端节点resolveValues错误

我无法从l20n-node Github页面运行示例代码,没有错误。

import { Env, fetchResource } from 'l20n'; const env = new Env('en-US', fetchResource); const ctx = env.createContext(['locales/{locale}.l20n']); const langs = [ {code: 'es-ES'}, {code: 'en-US'} ]; ctx.resolveValues(langs, ['foo', 'bar']).then( ([foo, bar]) => console.log(foo, bar)); 

首先它使用ES6导入语法,实际上并不是由节点应用的。 我编辑了一下:

 var Env = require('l20n').Env; var fetchResource = require('l20n').fetchResource; var env = new Env('ru', fetchResource); 

但还有一个问题: function resolveValues不存在。 有没有人有良好的实施node.js snippet for l20n? 需要严重

这是一个文档错误,我很抱歉的麻烦。 节点支持是实验性的, Env API是内部的,它改变了,没有相应的文档变化。 该文档现在是最新的 :

 const L20n = require('l20n'); const langs = [ {code: 'es-ES'}, {code: 'en-US'} ]; // fetchResource is node-specific, Env isn't const env = new L20n.Env(L20n.fetchResource); // helpful for debugging env.addEventListener('*', e => console.log(e)); // contexts are immutable; if langs change a new context must be created const ctx = env.createContext(langs, ['./locales/{locale}.l20n']); // pass string ids or tuples of [id, args] ctx.formatValues('foo', ['bar', {baz: 'Baz'}]).then(values => { // values is an array of resolved translations console.log(values); }); // -> ['Foo en español', 'Bar only exists in English'] 

为Node.js + Polymer + L20n集成创build了一个“案例研究”教程。
教程:基于L20n库的node.js / Polymer i18n解决scheme