Javascript l20n:服务器端节点解析值错误
我无法从l20n节点Github页面运行示例代码,而不会出现错误Javascript l20n:服务器端节点解析值错误,javascript,node.js,l20n,Javascript,Node.js,L20n,我无法从l20n节点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.resolveVa
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);
但还有另一个问题:函数resolveValues
不存在。
是否有人已经为l20n实现了node.js代码段?非常需要它这是一个文档错误,很抱歉给您添麻烦。节点支持是实验性的,
Env
API是内部的,它在没有对文档进行相应更改的情况下进行了更改。文件现在是:
为Node.js+Polymer+L20n集成创建了“案例研究”教程。
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']