
navigator.languages"af", "sq", "ar-SA", "ar-IQ", "ar-EG", "ar-LY", "ar-DZ", "ar-MA", "ar-TN", "ar-OM","ar-YE", "ar-SY", "ar-JO", "ar-LB", "ar-KW", "ar-AE", "ar-BH", "ar-QA", "eu", "bg","be", "ca", "zh-TW", "zh-CN", "zh-HK", "zh-SG", "hr", "cs", "da", "nl", "nl-BE", "en","en-US", "en-EG", "en-AU", "en-GB", "en-CA", "en-NZ", "en-IE", "en-ZA", "en-JM","en-BZ", "en-TT", "et", "fo", "fa", "fi", "fr", "fr-BE", "fr-CA", "fr-CH", "fr-LU","gd", "gd-IE", "de", "de-CH", "de-AT", "de-LU", "de-LI", "el", "he", "hi", "hu","is", "id", "it", "it-CH", "ja", "ko", "lv", "lt", "mk", "mt", "no", "pl","pt-BR", "pt", "rm", "ro", "ro-MO", "ru", "ru-MI", "sz", "sr", "sk", "sl", "sb","es", "es-AR", "es-GT", "es-CR", "es-PA", "es-DO", "es-MX", "es-VE", "es-CO","es-PE", "es-EC", "es-CL", "es-UY", "es-PY", "es-BO", "es-SV", "es-HN", "es-NI","es-PR", "sx", "sv", "sv-FI", "th", "ts", "tn", "tr", "uk", "ur", "ve", "vi", "xh","ji", "zu"]FormattedMessage组件中的信息parser后显示以<span>包裹的文本;*可以通过tagName指定其它标签包裹;*以id属性的值"hello"为索引——索引到自定义的映射表'./locale/zh_CN'中去;*messages['hello']——messages为父组件IntlProvider的props的messages属性;*若没有上述的返回值,则显示defaultMessage的值"React Intl Translations Example";*FormattedMessage添加子元素或ReactElement;* <FormattedMessage id="hello">* {(formattedValue)=>(* <em>{formattedValue}</em>* )}* </FormattedMessage><FormattedMessageid="hello"defaultMessage="React Intl Translations Example"/><FormattedMessage id="hello">{(formattedValue)=>(<em>{formattedValue}</em>)}</FormattedMessage><FormattedMessagetagName = 'p'id='superHello'defaultMessage="Locales:北京"values={{someone:'zxdobest'}}/>输出HTML块结构;import React from 'react';import { injectIntl, intlShape, FormattedMessage } from 'react-intl';const ChildComponent = ({ intl }) => {//传入的{intl}名称不可更改;console.log(React.PropTypes)const getMessage = intl.messages;return(<section>{/**通过intl.messages获取映射属性的方法;* 可以和任意内容(如:HTML标签)组合;* */}<a>{getMessage.hello}</a>{/*通过FormattedMessage格式化,可以传入参数{values}*/}<FormattedMessagetagName = 'p'id='superHello'defaultMessage="Locales:北京"values={{someone:'zxdobest'}}/>{/**这种结构,类同于intl.messages.superHello可以和其它内容任意组合;*能且仅能获取superHello的映射;* 目前尚未找到如果在第一种方法中传入values;*/}<FormattedMessage id="superHello" values={{someone:'mihuartuanr'}}>{(formattedValue)=>(<p>{formattedValue}</p>)}</FormattedMessage></section>);}ChildComponent.propTypes = {intl: intlShape.isRequired}export default injectIntl(ChildComponent);react-intl@2.9.0https://github.com/formatjs/babel-plugin-react-intlbabel-plugin-formatjsnpm i babel-plugin-react-intl@2.9.0 -DExtracts string messages for translation from modules that use React Intl.我使用babel-plugin-react-intl来自动提取我的React应用程序中的所有标签。我认为以下两点主要优势:使用插件,我的应用程序中的所有标签都会自动提取到json文件。而不必手动更新将被翻译的json文件。这样,我就不用担心这个文件了,因为插件会将标签贴到它上面。如果我不小心为标签创建了一个重复的ID,插件告诉我通过在webpack上抛出一个错误一旦完成了所有这些消息的翻译,你只需要使用babel-plugin react-intl插件来构建webpack。这将从代码库中提取所有定义的消息到JSON文件中。这些文件然后发送给你的翻译人员,他们翻译所有这些消息,并将翻译放入一个平坦的JSON哈希中,然后将其加载到你的代码中,并且您有一个支持i18n的应用程序。
chrome设置:高级设置-语言和输入设置
