neo-json-i18n
v2.1.0
Published
Translate json files over google translate
Downloads
20
Readme
neo-json-i18n
Translate json files over google translate
Installation
Via yarn
$ yarn global add neo-json-i18n
Via npm
$ npm install -g neo-json-i18n
CLI Usage
neo-json-i18n <src> [options]
Translate json files over google translate
Positionals:
src Source file [string]
Options:
--config, -c Configuration file. Defaults to "i18nconfig.json"
[string]
--output, -o Output directory [string]
--srcLang, -L Src language [string] [default: "auto"]
--lang, -l Target languages [array] [default: ["en"]]
--pattern, -p Output file name pattern
[string] [default: "%name_%lang.%ext"]
--cwd, -d Current working directory
[string] [default: "/Users/webber/www/node/neo-json-i18n"]
--spaces, -s JSON format spaces [string] [default: " "]
--help Show help [boolean]
--version Show version number [boolean]
Notes
pattern
supports these placeholders:%name
: file base name%lang
: output language%ext
: file extension name
- Language supports: plesase checkout here
Example
~/my/repo/dict.json
{ "film": "Star Wars" }
Open terminal, and run:
$ cd ~/my/repo/
$ neo-json-i18n dict.json --lang zh-cn,ja
It would create dict_zh-cn.json
and dict_ja.json
file as result
~/my/repo/dict_zh-cn.json
{ "film": "星球大战" }
~/my/repo/dict_ja.json
{ "film": "スターウォーズ" }
Node Module API Usage
import jsonI18n from "neo-json-i18n";
const json = { film: "Star Wars" };
jsonI18n(json, { lang: ["zh-cn", "ja"] })
.then(res => console.log(res))
.catch(err => console.error(err));
/*
* { 'zh-cn': { film: '星球大战' }, 'ja': { film: 'スターウォーズ' } }
*/
License
MIT