Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const cli = meow(
--flat json [default: true] | yaml [default: false]
--delimiter json | yaml [default: .]
--module-name module source name from where components are imported
--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'
Expand Down Expand Up @@ -50,6 +51,9 @@ const cli = meow(
},
'module-name': {
type: 'string'
},
extractFromFormatMessageCall: {
type: 'boolean'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ module.exports = async (locales, pattern, buildDir, opts) => {

const ext = isJson(opts.format) ? 'json' : 'yml'

const { defaultLocale, moduleName } = opts
const { defaultLocale, moduleName, extractFromFormatMessageCall } = opts

const delimiter = opts.delimiter ? opts.delimiter : '.'

const oldLocaleMaps = loadLocaleFiles(locales, buildDir, ext, delimiter)

const extractorOptions = { defaultLocale }
const extractorOptions = { defaultLocale, extractFromFormatMessageCall }

if (moduleName) {
extractorOptions.moduleSourceName = moduleName
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ $ extract-messages --help
--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'
Expand Down Expand Up @@ -178,6 +179,21 @@ Default: `react-intl`

Set from where _defineMessages_, `<FormatterMessage />` and `<FormattedHTML />` are imported.

##### extractFromFormatMessageCall

Type: `boolean`<br>
Default: `react-intl`

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',
})
```

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
Expand Down