diff --git a/cli.js b/cli.js
index 8281d9d..0d6f195 100755
--- a/cli.js
+++ b/cli.js
@@ -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'
@@ -50,6 +51,9 @@ const cli = meow(
},
'module-name': {
type: 'string'
+ },
+ extractFromFormatMessageCall: {
+ type: 'boolean'
}
}
}
diff --git a/index.js b/index.js
index 6bb787f..0fe8eb4 100644
--- a/index.js
+++ b/index.js
@@ -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
diff --git a/readme.md b/readme.md
index 3971f6d..b01c5e6 100644
--- a/readme.md
+++ b/readme.md
@@ -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'
@@ -178,6 +179,21 @@ Default: `react-intl`
Set from where _defineMessages_, `` and `` are imported.
+##### extractFromFormatMessageCall
+
+Type: `boolean`
+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)):