From 9395592ef7a6f24e7e3d6327c6a603638f6afc51 Mon Sep 17 00:00:00 2001 From: akameco Date: Sat, 24 Aug 2019 22:27:08 +0900 Subject: [PATCH] feat: extractFromFormatMessageCall true --- readme.md | 2 +- src/index.ts | 1 + src/test/fixtures/default/a/App.js | 11 +++++++++++ src/test/json/__snapshots__/test.ts.snap | 6 ++++++ src/test/yaml/__snapshots__/test.ts.snap | 6 ++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/fixtures/default/a/App.js diff --git a/readme.md b/readme.md index a4f7261..28a9f31 100644 --- a/readme.md +++ b/readme.md @@ -51,7 +51,7 @@ export const SubmitButton = () => { ### Run Script ``` -$ extract-messages -l=en,ja -o app/translations -d en --flat false --extractFromFormatMessageCall=true 'app/**/!(*.test).js' +$ extract-messages -l=en,ja -o app/translations -d en --flat false 'app/**/!(*.test).js' ``` ### Output diff --git a/src/index.ts b/src/index.ts index adf3169..70cad6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,6 +98,7 @@ export default async ( defaultLocale, withDescriptions: false, cwd: process.cwd(), + extractFromFormatMessageCall: true, ...opts } diff --git a/src/test/fixtures/default/a/App.js b/src/test/fixtures/default/a/App.js new file mode 100644 index 0000000..09eeedd --- /dev/null +++ b/src/test/fixtures/default/a/App.js @@ -0,0 +1,11 @@ +import React from 'react' +import { useIntl } from 'react-intl' + +export const SubmitButton = () => { + const intl = useIntl() + const label = intl.formatMessage({ + id: 'a.submit', + defaultMessage: 'Submit Button' + }) + return +} diff --git a/src/test/json/__snapshots__/test.ts.snap b/src/test/json/__snapshots__/test.ts.snap index a51c089..9403e15 100644 --- a/src/test/json/__snapshots__/test.ts.snap +++ b/src/test/json/__snapshots__/test.ts.snap @@ -4,6 +4,7 @@ exports[`export json - nest 1`] = ` Object { "a": Object { "hello": "hello", + "submit": "Submit Button", "world": "world", }, "b": Object { @@ -17,6 +18,7 @@ exports[`export json - nest 2`] = ` Object { "a": Object { "hello": "", + "submit": "", "world": "", }, "b": Object { @@ -29,6 +31,7 @@ Object { exports[`export json 1`] = ` Object { "a.hello": "hello", + "a.submit": "Submit Button", "a.world": "world", "b.hello": "hello", "b.world": "world", @@ -38,6 +41,7 @@ Object { exports[`export json 2`] = ` Object { "a.hello": "", + "a.submit": "", "a.world": "", "b.hello": "", "b.world": "", @@ -47,6 +51,7 @@ Object { exports[`export json with removed messages 1`] = ` Object { "a.hello": "hello", + "a.submit": "Submit Button", "a.world": "world", "b.hello": "hello", "b.world": "world", @@ -56,6 +61,7 @@ Object { exports[`export json with removed messages 2`] = ` Object { "a.hello": "", + "a.submit": "", "a.world": "", "b.hello": "", "b.world": "", diff --git a/src/test/yaml/__snapshots__/test.ts.snap b/src/test/yaml/__snapshots__/test.ts.snap index 07b4efc..d2816d2 100644 --- a/src/test/yaml/__snapshots__/test.ts.snap +++ b/src/test/yaml/__snapshots__/test.ts.snap @@ -3,6 +3,7 @@ exports[`export yaml - flat 1`] = ` Object { "a.hello": "hello", + "a.submit": "Submit Button", "a.world": "world", "b.hello": "hello", "b.world": "world", @@ -12,6 +13,7 @@ Object { exports[`export yaml - flat 2`] = ` Object { "a.hello": "", + "a.submit": "", "a.world": "", "b.hello": "", "b.world": "", @@ -22,6 +24,7 @@ exports[`export yaml 1`] = ` Object { "a": Object { "hello": "hello", + "submit": "Submit Button", "world": "world", }, "b": Object { @@ -35,6 +38,7 @@ exports[`export yaml 2`] = ` Object { "a": Object { "hello": "", + "submit": "", "world": "", }, "b": Object { @@ -48,6 +52,7 @@ exports[`exsit yaml 1`] = ` Object { "a": Object { "hello": "hello", + "submit": "Submit Button", "world": "world", }, "b": Object { @@ -61,6 +66,7 @@ exports[`exsit yaml 2`] = ` Object { "a": Object { "hello": "hello2", + "submit": "", "world": "", }, "b": Object {