2.0.1 • Published 6 years ago
i18n-json-compiler v2.0.1
i18n-json-compiler
A library to compile i18n json strings to target language format strings and functions.
Version 2.0
The output format changed:
- use one object to hold all variables, rather than use deep object
Support languages:
- TypeScript
Install
yarn global add i18n-json-compiler
# or npm
npm i -g i18n-json-compiler
Command line usage
i18n [options] - Parse i18n json files to typescript files.
Options:
-i, --input-files The json files to parse [string] [required]
-o, --output-dir The directory to emit output [string] [required]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
--default-lang [string] [default: "cn"]
The json file format: it's a array with each element is a map which key is the language and the value is the format of the string.
The format schema of the string: a parameter should be wrapped by '{' , '}', in the bracket pair, contains three part
of the parameter: name
, type
, default value
. with format {name:type=default value}
, the name
field is required,
and the type
and default value
is optional.
[
{
"en": "hello world {count:int=1} times.",
"cn": "世界你好 {count:int=1} 次."
}
]
Example
See example
TODO
- Normalize all language's function signature
- mangle all strings to one file
- compile to json rather language relative, for load dynamically