Extract react-intl messages compact version by tmkasun
npm install extract-react-intl-messages-compact




This package will generate json or yaml files from a glob. It will generate one file per locale, with the ids of each message defined by the defineMessages function of react-intl. The value of each of these keys will be an empty string, except for your defaultLocale which will be populated with the defaultMessage.
- 1.x works with Babel 7
- 0.x works with Babel 6
```
$ npm install --save-dev extract-react-intl-messages
app/components/App/messages.js
`js
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'a.hello',
defaultMessage: 'hello'
},
world: {
id: 'a.world',
defaultMessage: 'world'
}
})
`
``
$ extract-messages -l=en,ja -o app/translations -d en --flat false 'app/*/!(.test).js'
app/translations/en.json
`json`
{
"a": {
"hello": "hello",
"world": "world"
},
"b": {
"hello": "hello",
"world": "world"
}
}
app/translations/ja.json
`json`
{
"a": {
"hello": "",
"world": ""
},
"b": {
"hello": "",
"world": ""
}
}
Use with babel-plugin-react-intl-auto: i18n for the component age. Auto management react-intl ID.
`console
$ extract-messages --help
Extract react-intl messages
Usage
$ extract-react-intl-messages
$ extract-messages
Options
-o, --output Output directory [require: true]
-l, --locales locales [require: true]
-f, --format json|yaml [default: json]
--flat json [default: true] | yaml [default: false]
--default-locale default locale [default: en]
--delimiter json | yaml [default: .]
--module-name module source name from where components are imported [default: react-intl]
--extractFromFormatMessageCall If set to true, Command will extract the messages and IDs from intl.formatMessage calls
Example
$ extract-messages --locales=ja,en --output app/translations 'app/*/.js'
$ extract-messages -l=ja,en -o i18n 'src/*/.js'
$ extract-messages -l=ja,en -o app/translations -f yaml 'app/**/messages.js'
`
create .babelrc like this.
`json`
{
"presets": ["react-app"]
}
Run with NODE_ENV=development.
``
$ NODE_ENV=development extract-messages ...
#### locales
Type: Array
Example: ['en', 'ja']
#### input
Type: Array
Target files.
glob.
#### buildDir
Type: string
Export directory.
#### options
##### defaultLocale
Type: stringen
Default:
##### format
Type: json | yamljson
Default:
Set extension to output.
##### flat
Type: booleantrue
Default:
If format is yaml, set to false.
Be careful if false.
See this issue.
##### moduleName
Type: stringreact-intl
Default:
Set from where _defineMessages_, and are imported.
##### extractFromFormatMessageCall
Type: booleanreact-intl
Default:
If the value is true, Extractor will extract the i18n message and ID from intl.formatMessage calls as well.
i:e
```
intl.formatMessage({
id: 'Supported.file.types',
defaultMessage: 'Supported file types',
})
Thanks goes to these wonderful people (emoji key):
akameco 💻 ⚠️ 📖 🚇 | Hoan Tran 💻 ⚠️ | giantpinkwalrus 💻 | enrique-ramirez 📖 | Stefan Gojan 🐛 💻 ⚠️ | Solomon English 💻 | Filip "Filson" Pasternak 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT © akameco