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!' />







        




  • 相关阅读:
    ansible源码解读
    python标准模块(下)
    python学习之算法、自定义模块、系统标准模块(上)
    pathon 基础学习-集合(set),单双队列,深浅copy,内置函数
    python的map,filter,reduce学习
    python 列表
    python生成器、装饰器、正则
    python 模块学习
    python基础学习(一)--数据类型
    时间复杂度的计算
  • 原文地址:https://www.cnblogs.com/wangrui38/p/8268237.html
Copyright © 2011-2022 走看看