https://github.com/acyortjs/i18n
Node i18n
https://github.com/acyortjs/i18n
Last synced: about 1 month ago
JSON representation
Node i18n
- Host: GitHub
- URL: https://github.com/acyortjs/i18n
- Owner: acyortjs
- License: mit
- Created: 2018-11-02T00:54:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-20T05:45:04.000Z (over 7 years ago)
- Last Synced: 2025-02-24T17:50:45.104Z (over 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# i18n
[](https://travis-ci.org/acyortjs/i18n)
[](https://codecov.io/gh/acyortjs/i18n)
Node i18n
## Install
```bash
$ npm i @acyort/i18n -S
```
## Usage
```
const i18n = new I18n(dir, [locale]) // initial
i18n.locale = 'en' // set locale
const locale = i18n.locale // get current locale
```
```yml
# language
three: Hello %s
num:
zero: not cats
one: only one cats
other: is %d cats
a:
b:
c: s%2$s a %1$s
```
```js
const I18n = require('@acyort/i18n')
const { join } = require('path')
let i18n = new I18n(join(__dirname, 'locales'))
i18n.locale = 'default'
i18n.__('three', 'aaaa') // 'Hello aaaa'
i18n.__('a.b.c', 'aaaa', 'bbbb') // 'sbbbb a aaaa'
i18n._n('num', 0) // 'not cats'
i18n._n('num', 1) // 'only one cats'
i18n._n('num', 1000) // 'is 1000 cats'
i18n = new I18n(join(__dirname, 'locales'), 'default')
console.log(i18n.locale) // 'default'
i18n._n('num', 1000) // 'is 1000 cats'
```