1.0.0-beta.0 • Published 4 years ago
i18n-bundler v1.0.0-beta.0
webpack i18n modules
Webpack plugin that brings support for a modular approach to working with dictionaries for tools such as Phraseapp. Same as CSS Modules, but for i18n.
Usage:
In your webpack config:
const I18nModules = require('webpack-i18n-modules');
//...
plugins: [
new I18nModules(),
],
Create an options RC file in your project's root named .i18n-modules-rc.js
with this example content:
module.exports = {
// Opional, your keys will be relative to this folder, usually `./app` or `./client`
keysRoot: './',
// Opional, how you will be naming your translation modules, similar to name.module.css
moduleEnding: '.translations.json',
// Usually the same as the location in phraseapp.yml
// Can be a folder or a JSON file with [locale_code] to be replaced with the language name.
dictionaryPattern: './dictionaries/[locale_code].json',
};
If you don't expect to use the CLI (see below), then instead of creating the RC file you can simply pass an options object as an argument to the plugin.
Options:
keysRoot
(optional) - the keys will be generated relative to this folder. Use to make keys shorter by excluding static parts of the path, e.g. if all your translations are in./frontend/app/components
pass that as thekeysRoot
. Defaults toprocess.cwd()
moduleEnding
(optional) - the ending that will be used for the translation modules. You can't use:
in file names for these files. It's an OS limitation for MacOS and Windows anyway, but *nix users should be aware. Defaults to'.translations.json'
dictionaryPattern
(required) - the path to your dictionary folder or files. Use[locale_code]
placeholder to get current language name injected into the file name.
CLI:
This package comes with a CLI because you need a way to sync updates from Phraseapp or translations host back into your modules and a simple way to build all languages from modules at once. To use this CLI you must create an RC configuration file.
npx i18n-modules build
will build all dictionaries from modulesnpx i18n-modules update
will update all modules from dictionariesnpx i18n-modules clean
will remove all generated modules from dictionaries
An example with Phraseapp CLI:
npx i18n-modules build && phraseapp push
will push all generated modules to phraseappphraseapp pull && npx i18n-modules update
will update all modules with changes from phraseapp
1.0.0-beta.0
4 years ago