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 position, z-index
    Js闭包函数
    .net 全局配置读取
    redis学习
    .net core websocket
    .net core 部署应用程序注意事项
    signalr网上学习资料
    Cocos Creator 中如果Node在"属性检查器"中active设置为false, 则 onLoad 不会执行
    SVN服务器搭建(一)
    IndentityServer4
  • 原文地址:https://www.cnblogs.com/wangrui38/p/8268237.html
Copyright © 2011-2022 走看看