-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.jsx
48 lines (42 loc) · 1.09 KB
/
example.jsx
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
let React = require('react')
let ReactDOM = require('react-dom')
let {x18n, t} = require('react-x18n')
// Dictionary for english language
x18n.register('en', {
'greeting': 'Hello %{name}!',
'users_online': {
1: 'There is one user online.',
n: 'There are %1 users online.'
}
})
// Dictionary for german language
x18n.register('de', {
'greeting': 'Hallo %{name}!',
'users_online': {
1: 'Es ist ein Benutzer online.',
n: 'Es sind %1 Benuzer online.'
}
})
// Create react element
let App = React.createClass({
_changeDE: function () {
// Change language to german
x18n.set('de')
},
_changeEN: function () {
// Change language to english
x18n.set('en')
},
render: function () {
return <div>
{t('greeting', {name: 'Peter'})} <br />
{t.plural('users_online', 10)} <br />
{t.plural('users_online', 1)}
<hr />
<span onClick={this._changeDE}>Change language to DE</span> <br />
<span onClick={this._changeEN}>Change Language to EN</span>
</div>
}
})
// Render the app
ReactDOM.render(<App />, document.getElementById('app'))