开发者社区 问答 正文

#react 如何使用React Intl访问当前语言环境?

#react 如何使用React Intl访问当前语言环境?

展开
收起
因为相信,所以看见。 2020-05-07 20:30:32 937 分享 版权
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    您可以使用injectIntl()以下命令在应用程序的任何组件中获取当前语言环境:

    import { injectIntl, intlShape } from 'react-intl'

    const MyComponent = ({ intl }) => (

    {`The current locale is ${intl.locale}`}
    )

    MyComponent.propTypes = { intl: intlShape.isRequired }

    export default injectIntl(MyComponent)

    2020-05-07 20:30:53
    赞同 展开评论
问答分类:
问答地址: