Reactjs 如何使用react intl v2+;要加载区域设置文件的网页包?
我有一个使用webpack管理我所有资产的设置。它很好用。现在我计划使用react intl版本2来支持多种语言 我已设法使包“react intl”中定义的组件正常工作Reactjs 如何使用react intl v2+;要加载区域设置文件的网页包?,reactjs,internationalization,react-redux,react-intl,Reactjs,Internationalization,React Redux,React Intl,我有一个使用webpack管理我所有资产的设置。它很好用。现在我计划使用react intl版本2来支持多种语言 我已设法使包“react intl”中定义的组件正常工作 import {IntlProvider, FormattedNumber, FormattedPlural} from 'react-intl'; class App extends Component { constructor(props) { super(props); this.state = {
import {IntlProvider, FormattedNumber, FormattedPlural} from 'react-intl';
class App extends Component {
constructor(props) {
super(props);
this.state = {
name : 'Eric',
unreadCount: 1000,
};
}
render() {
const {name, unreadCount} = this.state;
return (
<p>
Hello <b>{name}</b>, you have {' '}
<FormattedNumber value={unreadCount} /> {' '}
<FormattedPlural value={unreadCount}
one="message"
other="messages"
/>.
</p>
);
}
}
从'react intl'导入{IntlProvider,FormattedNumber,FormattedPlural};
类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
姓名:'埃里克',
未结帐:1000,
};
}
render(){
const{name,unreadCount}=this.state;
返回(
你好{name},您有{'}
{' '}
.
);
}
}
但我不知道通过Web包加载语言环境文件并在组件中引用它们的正确方法是什么。由于该软件包最近进行了突破性的升级,因此也没有太多关于它的文档。wiki页面目前为空
我想知道做这件事的正确方法是什么?熊庞,
我刚刚根据react intl v2中的翻译示例编写了一个网页包插件。希望它对你有用:
然后,webpack配置插件看起来像:
new TranslateWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'index.hbs', // Load a custom template
inject: 'body', // Inject all scripts into the body
chunks: [ 'app' ],
app: true
}),
和index.hbs:
window.App=