File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ $ npm install --save-dev extract-react-intl-messages
2626app/components/App/messages.js
2727
2828``` js
29- import { defineMessages } from ' react-intl'
29+ import { defineMessages , useIntl } from ' react-intl'
3030
3131export default defineMessages ({
3232 hello: {
@@ -38,6 +38,15 @@ export default defineMessages({
3838 defaultMessage: ' world'
3939 }
4040})
41+
42+ export const SubmitButton = () => {
43+ const intl = useIntl ()
44+ const label = intl .formatMessage ({
45+ id: ' a.submit' ,
46+ defaultMessage: ' Submit Button'
47+ })
48+ return < button aria- label= {label}> {label}< / button>
49+ })
4150```
4251
4352### Run Script
@@ -54,11 +63,8 @@ app/translations/en.json
5463{
5564 "a" : {
5665 "hello" : " hello" ,
57- "world" : " world"
58- },
59- "b" : {
60- "hello" : " hello" ,
61- "world" : " world"
66+ "world" : " world" ,
67+ "submit" : " Submit Button"
6268 }
6369}
6470```
@@ -69,11 +75,8 @@ app/translations/ja.json
6975{
7076 "a" : {
7177 "hello" : " " ,
72- "world" : " "
73- },
74- "b" : {
75- "hello" : " " ,
76- "world" : " "
78+ "world" : " " ,
79+ "submit" : " "
7780 }
7881}
7982```
You can’t perform that action at this time.
0 commit comments