https://github.com/open-node/open-i18n
https://github.com/open-node/open-i18n
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/open-node/open-i18n
- Owner: open-node
- Created: 2016-07-18T04:59:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-28T14:55:25.000Z (almost 8 years ago)
- Last Synced: 2025-02-22T02:03:30.294Z (4 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# open-i18n
=================[](https://travis-ci.org/open-node/open-i18n)
[](https://codecov.io/gh/open-node/open-i18n)## Quick start
npm install open-i18n --save## Usage
```js
var i18n = require('i18n');// languages System allow language
// locale Current request use lanuage
// language packages,
/*
{
"zh": {
"hello world": "你好世界。"
},
"en": {
"hello world": "Hello world."
}
}
*/
var t = i18n(languages, locale, LANGS).t;t('hello world'); // return "你好世界"
// middle-ware auto handle res.body when request error
server.use(i18n.middleWare(languages, defaultLanguage, LANGS))
```## Collect language items
find ./src/app -type f | node_modules/.bin/open-i18n read > bin/locale/application.pot
msgmerge -UN --no-wrap ./bin/locale/en.po ./bin/locale/application.pot
msgmerge -UN --no-wrap ./bin/locale/zh.po ./bin/locale/application.pot## Translate language items
Edit `en.po`, `zh.po` to translate.
## Make language package
node_modules/.bin/open-i18n write ./bin/locale/zh.po zh > locale/zh.json