Skip to content

Commit 242753e

Browse files
authored
Support intl.formatMessage by default (#47)
1 parent 00c00f9 commit 242753e

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const SubmitButton = () => {
5151
### Run Script
5252

5353
```
54-
$ extract-messages -l=en,ja -o app/translations -d en --flat false --extractFromFormatMessageCall=true 'app/**/!(*.test).js'
54+
$ extract-messages -l=en,ja -o app/translations -d en --flat false 'app/**/!(*.test).js'
5555
```
5656

5757
### Output

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default async (
9898
defaultLocale,
9999
withDescriptions: false,
100100
cwd: process.cwd(),
101+
extractFromFormatMessageCall: true,
101102
...opts
102103
}
103104

src/test/fixtures/default/a/App.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
import { useIntl } from 'react-intl'
3+
4+
export const SubmitButton = () => {
5+
const intl = useIntl()
6+
const label = intl.formatMessage({
7+
id: 'a.submit',
8+
defaultMessage: 'Submit Button'
9+
})
10+
return <button aria-label={label}>{label}</button>
11+
}

src/test/json/__snapshots__/test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`export json - nest 1`] = `
44
Object {
55
"a": Object {
66
"hello": "hello",
7+
"submit": "Submit Button",
78
"world": "world",
89
},
910
"b": Object {
@@ -17,6 +18,7 @@ exports[`export json - nest 2`] = `
1718
Object {
1819
"a": Object {
1920
"hello": "",
21+
"submit": "",
2022
"world": "",
2123
},
2224
"b": Object {
@@ -29,6 +31,7 @@ Object {
2931
exports[`export json 1`] = `
3032
Object {
3133
"a.hello": "hello",
34+
"a.submit": "Submit Button",
3235
"a.world": "world",
3336
"b.hello": "hello",
3437
"b.world": "world",
@@ -38,6 +41,7 @@ Object {
3841
exports[`export json 2`] = `
3942
Object {
4043
"a.hello": "",
44+
"a.submit": "",
4145
"a.world": "",
4246
"b.hello": "",
4347
"b.world": "",
@@ -47,6 +51,7 @@ Object {
4751
exports[`export json with removed messages 1`] = `
4852
Object {
4953
"a.hello": "hello",
54+
"a.submit": "Submit Button",
5055
"a.world": "world",
5156
"b.hello": "hello",
5257
"b.world": "world",
@@ -56,6 +61,7 @@ Object {
5661
exports[`export json with removed messages 2`] = `
5762
Object {
5863
"a.hello": "",
64+
"a.submit": "",
5965
"a.world": "",
6066
"b.hello": "",
6167
"b.world": "",

src/test/yaml/__snapshots__/test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`export yaml - flat 1`] = `
44
Object {
55
"a.hello": "hello",
6+
"a.submit": "Submit Button",
67
"a.world": "world",
78
"b.hello": "hello",
89
"b.world": "world",
@@ -12,6 +13,7 @@ Object {
1213
exports[`export yaml - flat 2`] = `
1314
Object {
1415
"a.hello": "",
16+
"a.submit": "",
1517
"a.world": "",
1618
"b.hello": "",
1719
"b.world": "",
@@ -22,6 +24,7 @@ exports[`export yaml 1`] = `
2224
Object {
2325
"a": Object {
2426
"hello": "hello",
27+
"submit": "Submit Button",
2528
"world": "world",
2629
},
2730
"b": Object {
@@ -35,6 +38,7 @@ exports[`export yaml 2`] = `
3538
Object {
3639
"a": Object {
3740
"hello": "",
41+
"submit": "",
3842
"world": "",
3943
},
4044
"b": Object {
@@ -48,6 +52,7 @@ exports[`exsit yaml 1`] = `
4852
Object {
4953
"a": Object {
5054
"hello": "hello",
55+
"submit": "Submit Button",
5156
"world": "world",
5257
},
5358
"b": Object {
@@ -61,6 +66,7 @@ exports[`exsit yaml 2`] = `
6166
Object {
6267
"a": Object {
6368
"hello": "hello2",
69+
"submit": "",
6470
"world": "",
6571
},
6672
"b": Object {

0 commit comments

Comments
 (0)