gpt4 book ai didi

reactjs - i18n for React、formatjs、react-intl

转载 作者:行者123 更新时间:2023-12-03 13:16:58 24 4
gpt4 key购买 nike

我想在我的 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"
}
};

有解析器/转换器吗?

最佳答案

您应该检查此存储库 https://github.com/gpbl/isomorphic500 。 intl 子目录中有不同语言的输入文件。

你还可以看到他们采用的是哪种解析类型!希望这会有所帮助。

关于reactjs - i18n for React、formatjs、react-intl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31648886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com