@@ -14,8 +14,8 @@ import NavItem from 'react-bootstrap/lib/NavItem';
14
14
import Alert from 'react-bootstrap/lib/Alert' ;
15
15
import ReactCSSTransitionGroup from 'react-addons-css-transition-group' ;
16
16
import _ from 'lodash' ;
17
- import I18n from 'i18n-js ' ;
18
-
17
+ import { injectIntl , intlShape } from 'react-intl ' ;
18
+ import { defaultMessages } from '../../../common/i18nHelper' ;
19
19
import BaseComponent from 'libs/components/BaseComponent' ;
20
20
21
21
import css from './CommentForm.scss' ;
@@ -31,12 +31,13 @@ function bsStyleFor(propName, error) {
31
31
return null ;
32
32
}
33
33
34
- export default class CommentForm extends BaseComponent {
34
+ class CommentForm extends BaseComponent {
35
35
static propTypes = {
36
36
isSaving : PropTypes . bool . isRequired ,
37
37
actions : PropTypes . object . isRequired ,
38
38
error : PropTypes . any ,
39
39
cssTransitionGroupClassNames : PropTypes . object . isRequired ,
40
+ intl : intlShape . isRequired ,
40
41
} ;
41
42
42
43
constructor ( props , context ) {
@@ -123,18 +124,19 @@ export default class CommentForm extends BaseComponent {
123
124
}
124
125
125
126
formHorizontal ( ) {
127
+ const { formatMessage } = this . props . intl ;
126
128
return (
127
129
< div >
128
130
< hr />
129
131
< Form horizontal className = "commentForm form-horizontal" onSubmit = { this . handleSubmit } >
130
132
< FormGroup controlId = "formHorizontalName" >
131
133
< Col componentClass = { ControlLabel } sm = { 2 } >
132
- { I18n . t ( 'input.name.label' ) }
134
+ { formatMessage ( defaultMessages . inputNameLabel ) }
133
135
</ Col >
134
136
< Col sm = { 10 } >
135
137
< FormControl
136
138
type = "text"
137
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
139
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
138
140
ref = "horizontalAuthorNode"
139
141
value = { this . state . comment . author }
140
142
onChange = { this . handleChange }
@@ -145,13 +147,13 @@ export default class CommentForm extends BaseComponent {
145
147
</ FormGroup >
146
148
< FormGroup controlId = "formHorizontalName" >
147
149
< Col componentClass = { ControlLabel } sm = { 2 } >
148
- { I18n . t ( 'input.text.label' ) }
150
+ { formatMessage ( defaultMessages . inputTextLabel ) }
149
151
</ Col >
150
152
< Col sm = { 10 } >
151
153
< FormControl
152
154
type = "textarea"
153
155
label = "Text"
154
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
156
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
155
157
ref = "horizontalTextNode"
156
158
value = { this . state . comment . text }
157
159
onChange = { this . handleChange }
@@ -167,7 +169,9 @@ export default class CommentForm extends BaseComponent {
167
169
className = "btn btn-primary"
168
170
disabled = { this . props . isSaving }
169
171
>
170
- { this . props . isSaving ? `${ I18n . t ( 'input.saving' ) } ...` : I18n . t ( 'input.post' ) }
172
+ { this . props . isSaving
173
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
174
+ : formatMessage ( defaultMessages . inputPost ) }
171
175
</ Button >
172
176
</ Col >
173
177
</ FormGroup >
@@ -177,15 +181,16 @@ export default class CommentForm extends BaseComponent {
177
181
}
178
182
179
183
formStacked ( ) {
184
+ const { formatMessage } = this . props . intl ;
180
185
return (
181
186
< div >
182
187
< hr />
183
188
< form className = "commentForm form form-stacked" onSubmit = { this . handleSubmit } >
184
189
< FormGroup controlId = "formBasicName" >
185
- < ControlLabel > { I18n . t ( 'input.name.label' ) } </ ControlLabel >
190
+ < ControlLabel > { formatMessage ( defaultMessages . inputNameLabel ) } </ ControlLabel >
186
191
< FormControl
187
192
type = "text"
188
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
193
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
189
194
ref = "stackedAuthorNode"
190
195
value = { this . state . comment . author }
191
196
onChange = { this . handleChange }
@@ -196,11 +201,11 @@ export default class CommentForm extends BaseComponent {
196
201
< FormGroup
197
202
controlId = "formBasicText"
198
203
>
199
- < ControlLabel > { I18n . t ( 'input.text.label' ) } </ ControlLabel >
204
+ < ControlLabel > { formatMessage ( defaultMessages . inputTextLabel ) } </ ControlLabel >
200
205
< FormControl
201
206
type = "textarea"
202
207
label = "Text"
203
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
208
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
204
209
ref = "stackedTextNode"
205
210
value = { this . state . comment . text }
206
211
onChange = { this . handleChange }
@@ -214,7 +219,9 @@ export default class CommentForm extends BaseComponent {
214
219
className = "btn btn-primary"
215
220
disabled = { this . props . isSaving }
216
221
>
217
- { this . props . isSaving ? `${ I18n . t ( 'input.saving' ) } ...` : I18n . t ( 'input.post' ) }
222
+ { this . props . isSaving
223
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
224
+ : formatMessage ( defaultMessages . inputPost ) }
218
225
</ Button >
219
226
</ FormGroup >
220
227
</ form >
@@ -224,17 +231,18 @@ export default class CommentForm extends BaseComponent {
224
231
225
232
// Head up! We have some CSS modules going on here with the className props below.
226
233
formInline ( ) {
234
+ const { formatMessage } = this . props . intl ;
227
235
return (
228
236
< div >
229
237
< hr />
230
238
< Form inline className = "commentForm" onSubmit = { this . handleSubmit } >
231
239
< FormGroup controlId = "formInlineName" >
232
240
< ControlLabel >
233
- { I18n . t ( 'input.name.label' ) }
241
+ { formatMessage ( defaultMessages . inputNameLabel ) }
234
242
</ ControlLabel >
235
243
< FormControl
236
244
type = "text"
237
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
245
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
238
246
ref = "inlineAuthorNode"
239
247
value = { this . state . comment . author }
240
248
onChange = { this . handleChange }
@@ -245,12 +253,12 @@ export default class CommentForm extends BaseComponent {
245
253
</ FormGroup >
246
254
< FormGroup controlId = "formInlineName" >
247
255
< ControlLabel >
248
- { I18n . t ( 'input.text.label' ) }
256
+ { formatMessage ( defaultMessages . inputTextLabel ) }
249
257
</ ControlLabel >
250
258
< FormControl
251
259
type = "textarea"
252
260
label = "Text"
253
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
261
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
254
262
ref = "inlineTextNode"
255
263
value = { this . state . comment . text }
256
264
onChange = { this . handleChange }
@@ -264,7 +272,9 @@ export default class CommentForm extends BaseComponent {
264
272
className = "btn btn-primary"
265
273
disabled = { this . props . isSaving }
266
274
>
267
- { this . props . isSaving ? `${ I18n . t ( 'input.saving' ) } ...` : I18n . t ( 'input.post' ) }
275
+ { this . props . isSaving
276
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
277
+ : formatMessage ( defaultMessages . inputPost ) }
268
278
</ Button >
269
279
</ Form >
270
280
</ div >
@@ -284,7 +294,7 @@ export default class CommentForm extends BaseComponent {
284
294
} , [ ] ) ;
285
295
286
296
return (
287
- < Alert bsStyle = " danger" key = " commentSubmissionError" >
297
+ < Alert bsStyle = ' danger' key = ' commentSubmissionError' >
288
298
< strong > Your comment was not saved!</ strong >
289
299
< ul >
290
300
{ errorElements }
@@ -310,6 +320,7 @@ export default class CommentForm extends BaseComponent {
310
320
}
311
321
312
322
const { cssTransitionGroupClassNames } = this . props ;
323
+ const { formatMessage } = this . props . intl ;
313
324
314
325
// For animation with ReactCSSTransitionGroup
315
326
// https://facebook.github.io/react/docs/animation.html
@@ -325,13 +336,15 @@ export default class CommentForm extends BaseComponent {
325
336
{ this . errorWarning ( ) }
326
337
</ ReactCSSTransitionGroup >
327
338
328
- < Nav bsStyle = " pills" activeKey = { this . state . formMode } onSelect = { this . handleSelect } >
329
- < NavItem eventKey = { 0 } > { I18n . t ( 'form.horizontal' ) } </ NavItem >
330
- < NavItem eventKey = { 1 } > { I18n . t ( 'form.stacked' ) } </ NavItem >
331
- < NavItem eventKey = { 2 } > { I18n . t ( 'form.inline' ) } </ NavItem >
339
+ < Nav bsStyle = ' pills' activeKey = { this . state . formMode } onSelect = { this . handleSelect } >
340
+ < NavItem eventKey = { 0 } > { formatMessage ( defaultMessages . formHorizontal ) } </ NavItem >
341
+ < NavItem eventKey = { 1 } > { formatMessage ( defaultMessages . formStacked ) } </ NavItem >
342
+ < NavItem eventKey = { 2 } > { formatMessage ( defaultMessages . formInline ) } </ NavItem >
332
343
</ Nav >
333
344
{ inputForm }
334
345
</ div >
335
346
) ;
336
347
}
337
348
}
349
+
350
+ export default injectIntl ( CommentForm ) ;
0 commit comments