Extract react-intl messages
npm install @digidem/extract-react-intl-messages




This is forked from
extract-react-intl-messages.
It removes un-used options (custom delimiter, exporting nested files, and yaml
export), and adds an option to export messages in the same format that Chrome
Apps use. We use this because the
translation service we use, crowdin.com, accepts this format of file, and will
include the description as context for the translator.
This package will generate json from a glob. It will generate one file per
locale, with the ids of each message defined by thedefineMessages
function of react-intl. The value of each
of these keys will be an empty string, or an object with the property message
an empty string, except for your defaultLocale which will be populated with
thedefaultMessage.
- 2.x works with Babel 7
- 1.x works with Babel 7
- 0.x works with Babel 6
``sh`
$ npm install --save-dev @digidem/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 'app/*/!(.test).js'
app/translations/en.json
`json`
{
"a.hello": "hello",
"a.world": "world",
"b.hello": "hello",
"b.world": "world"
}
}
app/translations/ja.json
`json`
{
"a.hello": "",
"a.world": "",
"b.hello": "",
"b.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]
--descriptions include descriptions in output [default: false]
--default-locale default locale [default: en]
--module-name module source name from where components are imported [default: react-intl]
Example
$ extract-messages --locales=ja,en --output app/translations 'app/*/.js'
$ extract-messages -l=ja,en -o i18n 'src/*/.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:
##### moduleName
Type: stringreact-intl
Default:
Set from where _defineMessages_, and are imported.
#### descriptions
Type: booleanfalse
Default:
Includes message descriptions in the returned object. Each message id property
will be an object with properties message and description instead of a
message string e.g.
`js``
{
en: {
'components/App/hello': {
message: 'hello',
description: 'hello message description'
},
'components/App/welcome': {
message: 'welcome to extract-react-intl',
description: 'welcome message description
}
},
ja: {
'components/App/hello': {
message: '',
description: 'hello message description'
},
'components/App/welcome': {
message: '',
description: 'welcome message description
}
}
}
Thanks goes to these wonderful people (emoji key):
akameco 💻 ⚠️ 📖 🚇 | Hoan Tran 💻 ⚠️ | giantpinkwalrus 💻 | enrique-ramirez 📖 | Stefan Gojan 🐛 💻 ⚠️ | Solomon English 💻 | Filip "Filson" Pasternak 💻 |
Gregor MacLennan 💻 📖 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT © akameco