This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 167
/
I18nDemo.jsx
61 lines (53 loc) · 1.53 KB
/
I18nDemo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { I18nProvider, i18nLoader } from 'terra-i18n';
class Demo extends React.Component {
constructor(props) {
super(props);
this.state = {
areTranslationsLoaded: false,
locale: 'en-US',
messages: {},
};
this.handleLocaleChange = this.handleLocaleChange.bind(this);
}
componentDidMount() {
i18nLoader(this.state.locale, this.setState, this);
}
handleLocaleChange(e) {
i18nLoader(e.target.value, this.setState, this);
}
render() {
if (!this.state.areTranslationsLoaded) {
return <div />;
}
return (
<I18nProvider
locale={this.state.locale}
messages={this.state.messages}
>
<FormattedMessage id="Terra.ajax.error" />
<label htmlFor="locale"> Current locale: {this.state.locale} </label>
<select value={this.state.locale} onChange={this.handleLocaleChange}>
<option value="en">en</option>
<option value="en-GB">en-GB</option>
<option value="en-US">en-US</option>
<option value="de">de</option>
<option value="es">es</option>
<option value="fr">fr</option>
<option value="nl">nl</option>
<option value="pt">pt</option>
<option value="fi-FI">fi-FI</option>
</select>
</I18nProvider>
);
}
}
Demo.propTypes = {
locale: PropTypes.string,
};
Demo.defaultProps = {
locale: 'en',
};
export default () => <Demo />;