Tool that helps manage i18n files in your project.
$ npm install -g i18n-manager
i18n-manager list [directory]
-f, --fill-missing Fill missing keys based on base file
-a, --sort Sort keys based on base file
-s, --save Write result to files (creates backup by default)
Important: If you want to save result of this command use -s
flag. It will create backup for default
appending _i18n-manager_backup_file
sufix to files that are modified.
-f, --fill-missing Fill missing keys based on base file
Given we have two i18n json files – en.json
:
{
"language": "English",
"capitol": "London",
"units": {
"time_hour": "hour",
"currency": "GBP",
"drink": "tea"
}
}
... and pl.json
:
{
"language": "Polski",
"capitol": "Warszawa",
"units": {
"time_hour": "godzina",
"currency": "PLN"
}
}
After running:
$ i18n-manager clean app/i18n -f en.json
...we should see output in console:
[ { language: 'Polski',
capitol: 'Warszawa',
units: { currency: 'PLN', time_hour: 'godzina', drink: 'tea' } } ]
Missing fields in pl.json
should be replaced with values from base en.json
file.
The most convinient option is to use all options at once:
$ i18n-manager clean app/i18n -fas en.json
It will:
- fill missing keys
- sort keys based on base file
- save result to files and creates backup for all fill that were changed
To run app in development mode use:
$ npm run dev
I will run typescript compiler in watch mode (-w
) and generate *.js
files in bin
directory.
To use i18n-manager
during develompment to test functionality, access it as:
$ node bin/src/i18n-manager.js <command> [options]
To run test use:
$ npm test
i18n-manager
uses jest
framework, so you can pass whatever argument jest
accepts.
For example to enable watch mode use:
$ npm test -- --watch
To generate code coverage report use:
$ npm run coverage:generate
It will save coverage raport to coverage/
directory.
Thera are two npm scripts related with testing: playground:create
and playground:clean
. First one will create some locales
you can use during development in test/playground
, second one, will clean that directory. Both are used when running
npm test
.
You can see documentation generated by type doc from docs/
directory.
To generate fresh one use:
$ npm run doc:generate