l20n: 服务器端节点 resolveValues 错误
l20n: server-side node resolveValues error
我无法 运行 来自 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 import语法,node实际上并没有应用。
我稍微编辑了一下:
var Env = require('l20n').Env;
var fetchResource = require('l20n').fetchResource;
var env = new Env('ru', fetchResource);
但是还有一个问题:function resolveValues
不存在。
有没有人有 l20n 的实施良好的 node.js 片段?急需
这是一个文档错误,很抱歉给您带来麻烦。 Node 支持是实验性的,Env
API 是内部的,它在没有对文档进行相应更改的情况下进行了更改。文档现在是 up-to-date:
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 集成创建了 'case study' 教程。
Tutorial: solution for node.js / Polymer i18n based on L20n library
我无法 运行 来自 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 import语法,node实际上并没有应用。 我稍微编辑了一下:
var Env = require('l20n').Env;
var fetchResource = require('l20n').fetchResource;
var env = new Env('ru', fetchResource);
但是还有一个问题:function resolveValues
不存在。
有没有人有 l20n 的实施良好的 node.js 片段?急需
这是一个文档错误,很抱歉给您带来麻烦。 Node 支持是实验性的,Env
API 是内部的,它在没有对文档进行相应更改的情况下进行了更改。文档现在是 up-to-date:
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 集成创建了 'case study' 教程。
Tutorial: solution for node.js / Polymer i18n based on L20n library