Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
update nodejs docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Feb 25, 2016
1 parent 2ce0276 commit c8bea28
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions docs/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,26 @@ Example resource files:
Example node script:

```javascript
import { Env, fetchResource } from 'l20n';

const env = new Env('en-US', fetchResource);
const ctx = env.createContext(['locales/{locale}.l20n']);
const L20n = require('l20n');
const langs = [
{code: 'es-ES'},
{code: 'en-US'}
];

ctx.resolveValues(langs, ['foo', 'bar']).then(
([foo, bar]) => console.log(foo, bar));
// 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'
// -> ['Foo en español', 'Bar only exists in English']
```

0 comments on commit c8bea28

Please sign in to comment.