/
main.js
48 lines (38 loc) · 1.11 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react'
import {PropTypes} from 'prop-types'
import {connect} from 'react-redux'
import {setLanguage} from 'redux-i18n'
class Main extends React.Component {
constructor(props) {
super(props)
this.languages = ['es', 'en', 'de-DE']
}
componentWillMount() {
this.props.dispatch(setLanguage('en'))
}
onChangeLang = (e) => {
this.props.dispatch(setLanguage(e.target.value))
}
render() {
const user = {name: 'Cesc'}
const name = <b>{user.name}</b>
return (
<div>
<h1>Translations Dict</h1>
Language: {this.props.lang}<br/>
Change language:
<select value={this.props.lang} onChange={this.onChangeLang}>
{this.languages.map(lang => <option key={lang} value={lang}>{lang}</option>)}
</select><br/>
Translation: {this.context.t('Hello world!')}<br/>
Translation 2: <span dangerouslySetInnerHTML={{ __html: this.context.t('Hello {name}', {name: name})}}/>
</div>
)
}
}
Main.contextTypes = {
t: PropTypes.func.isRequired
}
export default connect(state => ({
lang: state.i18nState.lang
}))(Main)