https://github.com/rumkin/i18now
Simple internationalisation library with custom parsers support
https://github.com/rumkin/i18now
Last synced: 12 months ago
JSON representation
Simple internationalisation library with custom parsers support
- Host: GitHub
- URL: https://github.com/rumkin/i18now
- Owner: rumkin
- Created: 2016-05-10T14:13:53.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-12T14:47:48.000Z (about 10 years ago)
- Last Synced: 2025-03-25T00:59:18.842Z (about 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# i18now
Internationalization library based on Proxy object with subtemplates
and variable templates substitutions:
**100%** Code coverage.
# Installation
```bash
npm i i18now
```
## Usage
Create dictionary
```javascript
var t = i18now({
dict: {
// Regular message
hello: 'Hello',
// Template with substitution and subtemplate
greeting: '{{# hello }} {{ name }}!',
// Template with variable templates
gender: '{{## gender }}',
m: 'male',
f: 'female',
},
cache: true
});
t.greeting({name: 'User'}); // => "Hello User"
t.gender({gender: 'm'}); // => "male"
t.gender({gender: 'f'}); // => "female"
```
Multiple dictionaries usage see in [repository](https://github.com/rumkin/i18now)
examples directory.
### Constructor options
* dict – `object`. Dictionary object where key is message ID and value is message template.
* cache – `boolean`. Enable compilation result caching.
* compiler `Compiler`. Message templates compiler.
## Custom templates compiler
i18now allow to use custom compiler. It should accepts string and return
function which accepts two arguments: locals and options. Options contains
`templates` property and actually it's a dict itself.
Call of abstract compiler will look like so:
```
compiler.compile(str)(locals, {templates});
```