- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在我的 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/
使用 react-intl 我得到以下消息: serviceFee: { en: 'Service fee: ({fee, number, percent})', ... }, 当我打电话
Formatjs 提供了一个 babel plugin对于使用 react-intl 注入(inject)消息 ID 并删除 description 的模块。我如何将它与 Vite 一起使用? 最佳答
我想在我的 React 应用程序中为我的 i18n 使用 ICU 标准。我想存储我的语言文件,例如 http://userguide.icu-project.org/locale/localizing
是否可以在 FormatJS 消息中使用 if/else? 例子 我有一个 bool 变量 isDay 应该确定显示什么消息。当 true 时,我想显示“Day”字样,当 false 时,我想显示 N
是否可以在 FormatJS 消息中使用 if/else? 例子 我有一个 bool 变量 isDay 应该确定显示什么消息。当 true 时,我想显示“Day”字样,当 false 时,我想显示 N
我正在将 react-intl 迁移到 3.0 版,并且需要为 IE 填充语言环境数据。具体来说,我想为 en-US 加载区域设置数据的 polyfill。我只能找到@formatjs/intl-re
真的很愚蠢的问题 - 正确的 glob 格式是什么?我正在努力奔跑 formatjs extract ./src/**/*.js 但它只深入一层。 最佳答案 对于出现在这个问题上的人: formatj
我是一名优秀的程序员,十分优秀!