Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martypdx/ractive-l20n
Library for l20n of Ractive templates
https://github.com/martypdx/ractive-l20n
Last synced: about 10 hours ago
JSON representation
Library for l20n of Ractive templates
- Host: GitHub
- URL: https://github.com/martypdx/ractive-l20n
- Owner: martypdx
- Created: 2014-04-13T03:32:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-13T04:17:33.000Z (over 10 years ago)
- Last Synced: 2024-10-12T14:50:08.906Z (about 1 month ago)
- Language: JavaScript
- Homepage: http://martypdx.github.io/ractive-l20n/
- Size: 230 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Ractive l20n
====Experiment in localizing compiled Ractive templates.
http://martypdx.github.io/ractive-l20n/
```js
var ractive = require('ractive'),
template = 'hello {{world}}
',
parsed = ractive.parse(template)var l20n = require('./lib/l20n.js'),
dictionary = l20n.index(parsed)// dictionary is map of keypaths and string
// values extracted from the template:
//
// { "0.f.0.f": "hello", "0.f.1": " " }//edit dictionary
dictionary['0.f.0.f'] = "bonjour"var translated = l20n.translate(parsed, dictionary)
console.log(JSON.stringify(translated))
//bonjour {{world}}
```## install and use ##
Currently not yet packaged for npm, require the
`./lib/l20n.js` file for node use.`ractive-l20n.js` is browserified version that includes Ractive.
### `.index(parsed)` ###
Index the strings in a Ractive template that has been compiled
with `ractive.parse()`, returning a dictionary.### `.translate(parsed, dictionary)` ###
Returns a new version of the compiled Ractive template with the
new strings.## editing the dictionary ##
Because the dictionary is _just_ JSON, idea is that editor could
be built for making translations. `index.html` is a crude sample web page
for editing the dictionary and seeing live changes.There is an issue iterating on keypath-like
properties, so the current editor is just a text area, as opposed
to individual fields.## whitespace ##
Currently pure whitespace nodes are returned as well. These could be
filtered out.One thing to bear in mind is that whitespace around text
is significant:```html
hello {{name}}
```If we change the dictionary entry `"hello "` to "bonjour", template
will render as "bonjourjean".One possiblity would be to parse leading and trailing whitespace and
store seperate from the editing value.## test ##
Test cases can be added to `test/120n.test.js`. Test are run with:```sh
$ mocha test
```