babel-plugin-intl v0.1.1
babel-plugin-intl
Extracts string messages for translation from modules that use intl.
Note: This Babel plugin is based on babel-plugin-react-intl and works with Babel 6.
Installation
$ npm install babel-plugin-intlUsage
This Babel plugin only visits ES6 modules which import intl.
The default message descriptors for the app's default language will be extracted from intl(), which is a default export of the intl package.
Via .babelrc (Recommended)
.babelrc
{
"plugins": [
[
"intl", {
"messagesDir": "./build/messages/",
"enforceDescriptions": false
}
]
]
}Options
messagesDir: The target location where the plugin will output a.jsonfile corresponding to each call from whichintlmessages were extracted. If not provided, the extracted message descriptors will only be accessible via Babel's API.enforceDescriptions: Whether or not message declarations must contain adescriptionto provide context to translators. Defaults to:false.moduleSourceName: The ES6 module source name of theintlpackage. Defaults to:"./intl", but can be changed to another name/path.
Via CLI
$ babel --plugins intl script.jsVia Node API
The extract message descriptors are available via the metadata property on the object returned from Babel's transform() API:
require('babel-core').transform('code', {
plugins: ['intl']
}) // => { code, map, ast, metadata['intl'].messages };