Skip to content

Commit 1502b36

Browse files
committed
add i18n functionality to view(non-Flux framework)
1 parent 1e51629 commit 1502b36

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

client/app/bundles/comments/components/SimpleCommentScreen/SimpleCommentScreen.jsx

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,52 @@ import Immutable from 'immutable';
33
import _ from 'lodash';
44
import React from 'react';
55
import ReactOnRails from 'react-on-rails';
6-
6+
import { IntlProvider, injectIntl, intlShape } from 'react-intl';
77
import BaseComponent from 'libs/components/BaseComponent';
88

99
import CommentForm from '../CommentBox/CommentForm/CommentForm';
1010
import CommentList from '../CommentBox/CommentList/CommentList';
1111
import css from './SimpleCommentScreen.scss';
12+
import { SelectLanguage } from 'libs/i18n/selectLanguage';
13+
import { defaultMessages, defaultLocale } from 'libs/i18n/default';
14+
import { translations } from 'libs/i18n/translations';
15+
16+
export default class I18nWrapper extends BaseComponent {
17+
constructor(props) {
18+
super(props);
19+
20+
this.state = {
21+
locale: defaultLocale,
22+
};
23+
24+
_.bindAll(this, 'handleSetLocale');
25+
}
26+
27+
handleSetLocale(locale) {
28+
this.setState({ locale: locale });
29+
}
30+
31+
render() {
32+
const { locale } = this.state;
33+
const messages = translations[locale];
34+
const InjectedSimpleCommentScreen = injectIntl(SimpleCommentScreen);
35+
36+
return (
37+
<IntlProvider locale={locale} key={locale} messages={messages}>
38+
<InjectedSimpleCommentScreen
39+
{...this.props}
40+
locale={locale}
41+
handleSetLocale={this.handleSetLocale}
42+
/>
43+
</IntlProvider>
44+
);
45+
}
46+
}
47+
48+
class SimpleCommentScreen extends BaseComponent {
49+
constructor(props) {
50+
super(props);
1251

13-
export default class SimpleCommentScreen extends BaseComponent {
14-
constructor(props, context) {
15-
super(props, context);
1652
this.state = {
1753
$$comments: Immutable.fromJS([]),
1854
isSaving: false,
@@ -67,6 +103,8 @@ export default class SimpleCommentScreen extends BaseComponent {
67103
}
68104

69105
render() {
106+
const { handleSetLocale, locale, intl } = this.props;
107+
const { formatMessage } = intl;
70108
const cssTransitionGroupClassNames = {
71109
enter: css.elementEnter,
72110
enterActive: css.elementEnterActive,
@@ -75,12 +113,16 @@ export default class SimpleCommentScreen extends BaseComponent {
75113
};
76114

77115
return (
78-
<div className="commentBox container">
79-
<h2>Comments</h2>
80-
<p>
81-
Text take Github Flavored Markdown. Comments older than 24 hours are deleted.<br />
82-
<b>Name</b> is preserved. <b>Text</b> is reset, between submits.
83-
</p>
116+
<div className='commentBox container'>
117+
<h2>
118+
{formatMessage(defaultMessages.comments)}
119+
</h2>
120+
{ SelectLanguage(handleSetLocale, locale) }
121+
<ul>
122+
<li>{formatMessage(defaultMessages.descriptionSupportMarkdown)}</li>
123+
<li>{formatMessage(defaultMessages.descriptionDeleteRule)}</li>
124+
<li>{formatMessage(defaultMessages.descriptionSubmitRule)}</li>
125+
</ul>
84126
<CommentForm
85127
isSaving={this.state.isSaving}
86128
actions={{ submitComment: this.handleCommentSubmit }}

0 commit comments

Comments
 (0)