我想在我的react应用程序中对我的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, plural,\n =0 {no photos}\n =1 {one photo}\n other {# photos}\n} on {takenDate, date, long}.\n" }
}转换为以下格式:
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"
}
};到底有没有解析器/转换器?
发布于 2015-07-27 20:29:50
您应该检查此存储库https://github.com/gpbl/isomorphic500。在intl子目录中有不同语言的输入文件。
您还可以看到它们采用了哪种类型的解析!希望这能有所帮助。
https://stackoverflow.com/questions/31648886
复制相似问题