webext-i18n
This package simplifies work with i18n in WebExtensions.
Install
npm install webext-i18n --save-dev
Usage
For instance, you have the following structure:
src
└── locales
├── en.js
└── de.js
And en.js
may contain something like that:
popup: title: 'Super title' description: 'Super description' buttons: login: 'Login' remove: 'Remove account' contentScript: action: 'Super action name' text: 'Lorem ipsum' items: 'First item' 'Second item'
Yeah, nested translation entities without specifying message
field! And yes, it's not an appropriate format for WebExtensions, so you need to run the code below to generate a proper locales files:
const i18n = ;
It will create dist/locales
directory with en.json
and de.json
files inside. And en.json
looks like that:
API
The package contains only one method (the default export).
Options
-
inputDir
- directory with locales. -
outputDir
- directory where generated files should be placed.
Returns a Promise
that will be resolved when all locales are generated.