reactjs – i18n进行反应,formatjs,react-intl
发布时间:2020-12-15 20:51:40 所属栏目:百科 来源:网络整理
导读:我想在我的反应应用程序中使用我的i18n的ICU标准.我想存储我的语言文件,如 http://userguide.icu-project.org/locale/localizing#TOC-.txt-resource-bundles: de { key1 { "Deutsche Sprache " "schwere Sprache" } key2 { "Düsseldorf" }} 我发现这个库ht
我想在我的反应应用程序中使用我的i18n的ICU标准.我想存储我的语言文件,如
http://userguide.icu-project.org/locale/localizing#TOC-.txt-resource-bundles:
de { key1 { "Deutsche Sprache " "schwere Sprache" } key2 { "Düsseldorf" } } 我发现这个库http://formatjs.io/react/. http://formatjs.io/支持ICU,但是我找不到任何好的例子,如何连接我的应用程序的语言文件. 我正在通过他们的教程,看来我可以使用组件< FormattedMessage> ;.例如 var intlData = { "locales": "en-US","messages": { "photos": "{name} took {numPhotos,plural,n =0 {no photos}n =1 {one photo}n other {# photos}n} on {takenDate,date,long}.n" } }; React.render( <Component {...intlData} />,document.getElementById('example') ); 那么在某些组件我有 ... render: function () { return ( <p> <FormattedMessage message={this.getIntlMessage('photos')} name="Annie" numPhotos={1000} takenDate={Date.now()} /> </p> ); } 我最大的问题是如何转换我的语言文件,例如 en-US { photos { "{name} took {numPhotos,long}.n" } } 转换成格式: var intlData = { "locales": "en-US",long}.n" } }; 有没有任何解析器/转换器?
您应该检查该存储库
https://github.com/gpbl/isomorphic500.在intl子目录中有不同语言的输入文件.
您还可以看到他们采用哪种类型的解析!希望这可以帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |