FormattedMessage を使用せずに翻訳テキストを取得する方法を探しています。これまでのところ 、React の EXPERIMENTAL 機能であるContextTypesの使用を提供するこのソリューションしか見つかりませんでした。これを達成する他の方法 (または他のライブラリ/npm モジュール) はありますか?
1 に答える
3
私は を使用することを好みますが、react-intl は代わりに使用できるcontext
高次コンポーネントも提供します。これは、すべての命令型書式設定関数を持つinjectIntl
prop を渡します。intl
import React from "react";
import {injectIntl, intlShape} from "react-intl";
class MyComponent extends React.Component {
static propTypes = {
intl: intlShape.isRequired
}
render() {
return <p>{this.props.intl.formatDate(new Date())}</p>;
}
}
export default injectIntl(Component);
于 2016-05-24T20:52:53.743 に答える