较为成熟,支持 hooks 使用。
https://www.npmjs.com/package/react-intl
npm install react-intl --save
hook:
const PostDate = ({date}) => {
const intl = useIntl()
return (
<span title={intl.formatDate(date)}>
<FormattedRelativeTime value={(Date.now() - date)/MS_IN_DAY} unit="day"/>
</span>
)
});
高阶组件,包裹:
export default connect(mapStateToProps,mapActionCreators)(injectIntl(App))
使用:
const {intl} = this.props;
let tmp = intl.formatMessage({id: 'intl.name'},{name: 'joe'});