mojito-rb-gen
v0.0.1
Published
Localization utility that converts .properties files into JS/JSON resource bundles
Maintainers
Readme
mojito-rb-gen
Localization utility that converts .properties files into JSON/JS resource bundles.
Install
npm install -g mojito-rb-gen
Usage
Each .properties files in the source directory will be converted into a JSON or JS resource bundle.
One of the .properties file is the source resource bundle (by default en.properties, use --source-bundle to
override) and contains the source strings that are usually modified during development. Other files contain
the localized strings.
The JSON/JS localized resource bundles are generated by merging the source strings with the translated strings from
the .properties files. This ensure that the localized resource bundles contain all the strings required by the application
even if the translations are not yet available.
Usage:
mojito-rb-gen [OPTIONS] [ARGS]
Options:
-s, --source-directory [PATH] Source directory (Default is .)
-o, --output-directory [PATH] Output directory (Default is .)
-b, --source-boundle [STRING] Source bundle file (Default is en.properties)
-n, --use-namespaces BOOLEAN Use namespaces when parsing properties files
-t, --output-type [STRING] Output type: json, js (Default is json)
-w, --watch BOOLEAN Watch the source directory for changes and rebuild
resource bundles
--js-variable [STRING] Varaible name used to generate Javascript file (Default is MESSAGES)
-k, --no-color Omit color from output
--debug Show debug information
-h, --help Display help and usage detailsMerge logic
With source bundle: en.properties
# Group 1 Key 1 Comment
group1.key1 = Group 1 Key 1
group1.key2 = Group 1 Key 2
group2.key1 = Group 1 Key 1and localized properties: fr.properties
group1.key2 = Group 1 Key 2 (fr)
outdated = OutdatedThe merge output in JSON will be:
{"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"}Examples
Output types
JSON
$ mojito-rb-gen -s examples/src/ -o examples/out/json/{"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"}Javascript
$ mojito-rb-gen -s examples/src/ -o examples/out/js/default -t jsMESSAGES = {"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"};Configure Javascript variable name
$ mojito-rb-gen -s examples/src/ -o examples/out/js/var/ -t js --js-variable MY_MESSAGESMY_MESSAGES = {"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"};Use namespaces
$ mojito-rb-gen -s examples/src/ -o examples/out/js/namespaces/ -t js --js-variable MY_MESSAGES_NS -nMY_MESSAGES_NS = {"group1":{"key1":"Group 1 Key 1","key2":"Group 1 Key 2 (fr)"},"group2":{"key1":"Group 2 Key 1"},"outdated":"Outdated"};Watch source directory for changes and rebuild resources bundles
$ mojito-rb-gen -s examples/src/ -o out -w
INFO: Start watching: examples/src/
INFO: en.properties changed, generate resource bundlesUse a different source bundle
$ mojito-rb-gen -s examples/src/ -o out -b en-US.properties