Internationalization Tools
You can use this project as a stand alone global or as part of another project.
npm install -g i18n-tools
OR
npm install i18n-tools
Usage
Extract tokenized strings from handlebars templates to PO files.
i18n-tools-xgettext-hbs
i18n-tools-xgettext-hbs
--extension=*.hbs // the handlebars file extension
--views-dir=./test/lib/views // the handlebars template directory
--output-dir=./test/lang/en // the output directory for the PO file
--output-file=messages.po // the PO filename
--run
The handlebars template files have to be in the following structure to be extracted correctly
<button>{{__ "Sign in"}}</button>
<p>{{count}} {{__n "country" "countries" count}}</p>
__
: is for singlular tokens__n
: is for pluralized tokens
Convert PO files to JSON files
i18n-tools-po-to-json
i18n-tools-po-to-json
--filter=.*\.po // The regex PO file filter
--dir=./lang // The directory to scan for PO files
--run
This tool will look through all directories recursively from the passed --dir
and look for --filter
files. It will then attempt to convert them into valid JSON language files suitable for Jed.
Extract and convert to JSON files
i18n-tools-xgettext-to-json
i18n-tools-xgettext-to-json
--extension=*.hbs // the handlebars file extension
--views-dir=./test/lib/views // the handlebars template directory
--output-dir=./test/lang // the output directory for the PO file
--output-file=messages.po // the PO filename
--locale=en // The default locale that is used when extracting the templates
--run
This will extract tokens from the handlebars templates to PO files and then convert them to JSON files in one step.
Reverse String Generator
This is used primarily for testing your tokenisation efforts before you have your language files translated. This will reverse the primary PO file and produce a JSON language file to be consumed by your application.
i18n-tools-po-to-rv-json
i18n-tools-po-to-rv-json
--input-dir=test/lang/en
--output-dir=test/lang/rv
--run