|
1 |
| -var FormatMessage = require('../react-globalize').FormatMessage; |
2 |
| -var React = require('react'); |
3 |
| -var Globalize = require('globalize'); |
| 1 | +import React from "react"; |
| 2 | +import Globalize from "globalize"; |
| 3 | +import { FormatMessage } from "../react-globalize"; |
4 | 4 |
|
5 |
| -module.exports = React.createClass({ |
6 |
| - getInitialState: function() { |
7 |
| - return { |
8 |
| - locale: "en" |
9 |
| - }; |
10 |
| - }, |
11 |
| - handleChange: function( event ) { |
| 5 | + |
| 6 | +class LocalizedMessages extends React.Component { |
| 7 | + state = { |
| 8 | + locale: "en", |
| 9 | + }; |
| 10 | + handleChange = (event) => { |
12 | 11 | this.setState({
|
13 |
| - locale: event.target.value |
| 12 | + locale: event.target.value, |
14 | 13 | });
|
15 |
| - }, |
16 |
| - render: function() { |
| 14 | + } |
| 15 | + render() { |
17 | 16 | return (
|
18 | 17 | <div>
|
19 | 18 | <div>
|
@@ -42,9 +41,29 @@ module.exports = React.createClass({
|
42 | 41 | Bye
|
43 | 42 | </FormatMessage>
|
44 | 43 | <h3>Variable Replacement</h3>
|
45 |
| - ["Wolfgang", "Amadeus", "Mozart"] - <FormatMessage locale={this.state.locale} path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} /> |
46 |
| - <br/> |
47 |
| - {JSON.stringify({first:"Wolfgang", middle:"Amadeus", last:"Mozart"})} - <FormatMessage locale={this.state.locale} path="variables/hey" variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}} /> |
| 44 | + ["Wolfgang", "Amadeus", "Mozart"] - <FormatMessage locale={this.state.locale} path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} /> |
| 45 | + <br /> |
| 46 | + { JSON.stringify({ first: "Wolfgang", middle: "Amadeus", last: "Mozart" }) } - <FormatMessage locale={this.state.locale} path="variables/hey" variables={{ first: "Wolfgang", middle: "Amadeus", last: "Mozart" }} /> |
| 47 | + <h3>Element Replacement</h3> |
| 48 | + <FormatMessage |
| 49 | + locale={this.state.locale} |
| 50 | + elements={ |
| 51 | + // eslint-disable-next-line jsx-a11y/anchor-has-content, react/self-closing-comp |
| 52 | + { reactGlobalizeLink: <a href="https://github.com/jquery-support/react-globalize"></a> } |
| 53 | + } |
| 54 | + > |
| 55 | + For more information, see [reactGlobalizeLink]React Globalize[/reactGlobalizeLink] |
| 56 | + </FormatMessage> |
| 57 | + <br /> |
| 58 | + <FormatMessage |
| 59 | + locale={this.state.locale} |
| 60 | + elements={ |
| 61 | + // eslint-disable-next-line react/self-closing-comp |
| 62 | + { strong: <strong></strong> } |
| 63 | + } |
| 64 | + > |
| 65 | + Use Element Replacement to localize messages with [strong]markup[/strong] too. |
| 66 | + </FormatMessage> |
48 | 67 | <h3>Gender Inflection</h3>
|
49 | 68 | {JSON.stringify({guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"male"})} - <FormatMessage locale={this.state.locale} path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"male"}} />
|
50 | 69 | <br/>
|
@@ -72,4 +91,5 @@ module.exports = React.createClass({
|
72 | 91 | </div>
|
73 | 92 | );
|
74 | 93 | }
|
75 |
| -}); |
| 94 | +} |
| 95 | +export default LocalizedMessages; |
0 commit comments