babel-plugin-format-message
babel plugin to replace formatMessage calls with translations.
Installation
$ npm install babel-plugin-format-message
Usage
This plugin isn't terribly useful without configuration, so you probably won't
add it via the .babelrc
or CLI.
Via Node API
var formatMessagePlugin = require('babel-plugin-format-message');
require("babel-core").transform("code", {
plugins: [
formatMessagePlugin.withOptions({
})
]
});
Via webpack loader
var formatMessagePlugin = require('babel-plugin-format-message');
module.exports = [ "en", "pt", "de" ].map(function(locale) {
entry: "path/to/entry.js",
output: {
path: "path/to/output/",
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel" }
]
},
babel: {
plugins: [
formatMessagePlugin.withOptions({
})
]
}
});
Via browserify / babelify
var b = browserify({
}).transform(
babelify.configure({
plugins: [
formatMessagePlugin.withOptions({
})
]
})
);
Example options
See format-message for full options documentation.
{
functionName: "formatMessage",
locale: locale,
translate: function(pattern, locales) {
return require("path/to/translations/" + locale + ".json")[pattern];
},
translations: {
pt: { ... },
de: { ... }
},
keyType: "underscored_crc32",
missingTranslation: "warning",
missingReplacement: "!!NOT TRANSLATED!!"
}
License
This software is free to use under the MIT license.
See the LICENSE-MIT file for license text and copyright information.