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







        




  • 相关阅读:
    取模 分数取模 快速幂 费马小定理
    “科林明伦杯”哈尔滨理工大学第十届程序设计竞赛 部份签到题
    shell 脚本
    pyhcl语法
    数据库实验1 SQL
    杂七杂八 Ubuntu Linux
    Kattis, Kattis 的一些问题题解
    Meow Factor 【暴力】
    解决 Eclipse 项目有红感叹号的方法
    RuntimeException与CheckedException
  • 原文地址:https://www.cnblogs.com/wangrui38/p/8268237.html
Copyright © 2011-2022 走看看