Localization utility that converts .properties
files into JSON
/JS
resource bundles.
npm install -g mojito-rb-gen
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 details
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 1
and localized properties: fr.properties
group1.key2 = Group 1 Key 2 (fr)
outdated = Outdated
The 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"}
$ 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"}
$ mojito-rb-gen -s examples/src/ -o examples/out/js/default -t js
MESSAGES = {"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"};
$ mojito-rb-gen -s examples/src/ -o examples/out/js/var/ -t js --js-variable MY_MESSAGES
MY_MESSAGES = {"group1.key1":"Group 1 Key 1","group1.key2":"Group 1 Key 2 (fr)","group2.key1":"Group 2 Key 1","outdated":"Outdated"};
$ mojito-rb-gen -s examples/src/ -o examples/out/js/namespaces/ -t js --js-variable MY_MESSAGES_NS -n
MY_MESSAGES_NS = {"group1":{"key1":"Group 1 Key 1","key2":"Group 1 Key 2 (fr)"},"group2":{"key1":"Group 2 Key 1"},"outdated":"Outdated"};
$ mojito-rb-gen -s examples/src/ -o out -w
INFO: Start watching: examples/src/
INFO: en.properties changed, generate resource bundles
$ mojito-rb-gen -s examples/src/ -o out -b en-US.properties