我想在我的反应应用程序中使用我的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子目录中有不同语言的输入文件.
您还可以看到他们采用哪种类型的解析!希望这可以帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。