globalize-compiler-plus
v0.0.10
Published
Includes all messages in the globalize-compiler process even if not statically referenced
Downloads
3
Readme
Overview
Wraps globalize-compiler to allow for simpler use:
- Locales are inferred from Messages.json file
- All keys/values in Messages.json are compiled into the output, without having to reference them statically in the input .js files
Background
I started with globalize-webpack-plugin, but had some dislikes/issues:
- There is some narly stuff going on in this example at the bottom of file. I'd prefer complicating the build process over the product. See Usage below for how this tool approaches that problem (dynamically pulling locales, as needed)
- The example also unfortunately works for just one locale, and its unclear to me, being new to the JS world, what I would need to do to get that to work
- It is unusable for me. Partly documented here, you must statically reference every key (that you'd like bundled) in your message json.
This solution aims to simplify and close the gap on the above issues. I chose to build from globalize-compiler for a few reasons:
- It's 95% there
- CLI and simple function calls easier to reason about vs webpack and globalize internals. Something like KISS
- It's a more universal solution compatible with any build tool and UI tool (angular, react, riot, pure js vs rolling your own as suggested here)
Usage
The inputs provided to globalize-plus-compiler are of the same format of globalize-compiler, with the exception of locales
which can be a comma separated list, but isn't required. Locales, when not provided, are derived from the messages.json file.
One additional input argument is used for JS build helpers, such as webpack. It is a path to where the formatters live, relative to the app root, so that locales can be pulled dynamically, as needed.
Output is also exactly the same. Compiled JS files that contain the formatters and messages for the application and locale.
Use npm scripts, gulp tasks, etc... to run this.
CLI
> npm install globalize-compiler-plus --save-dev
> globalize-compiler-plus -m test/messages.json -a path/to/app/root -o test/output/ test/*.js
> tree test/output/
test/output/
├── formatters-de.js
├── formatters-en.js
├── formatters-es.js
└── webpack-helper.js
JS usage
Works, but TBD on docs...
Examples
https://github.com/lp-/webpack-riot-uikit-globalize-jsdata-template