zoukankan      html  css  js  c++  java
  • react-i8n

    1. 在项目中安装

      npm install react-intl --save

    2.兼容Safari各个版本需要安装intl

      npm install intl --save

    3.编写语言包

      1.)新建 en_US.js

        const = en_US = {

          hello: "Hello world !",

          superHello: "Hello, { someone } ! "

        }

      2.)  新建 zh_CN.js

        const = en_US = {

          hello: "你好 世界!",

          superHello: "你好, { someone } ! "

        }

    4.在最外层的 index.js中修改

      1.)引入文件  

        import { IntlProvider, addLocaleData } from 'react-intl';

        import zh_CN from './translations/zh_CN'

        import en_US from './translations/en_US'

      2.)在render里添加标签

        ReactDOM.render(
          <IntlProvider
            locale={'en'}
            messages={'en_US'}
          >
            <App/>
          </IntlProvider>, document.getElementById('root')
        );

    5.在任何组件内使用

      1.)引入

        import { FormattedMessage, FormattedDate, FormattedNumber } from 'react-intl';

      2.)使用组件

        <h3><FormattedNumber value={1000}/></h3>

        <FormattedMessage id='hello' values={{someone:<b>{'增加的中文'}</b>}} description='say hello to Howard' defaultMessage='你好, Howard!' />







        




  • 相关阅读:
    CSS&JS两种方式实现手风琴式折叠菜单
    MySQL创建数据库/表等基本命令操作
    web注册功能实现
    符合altium designer操作习惯的cadence快捷键设置
    运行Capture.exe找不到cdn_sfl401as.dll
    modelsim遇到的问题(更新)
    1.4 扩展
    1.3 Security
    1.2 Install Extension 安装扩展
    1.1 Modify Template修改模板
  • 原文地址:https://www.cnblogs.com/wangrui38/p/8268237.html
Copyright © 2011-2022 走看看