首页 > 解决方案 > 如何在组件标题中使用翻译?

问题描述

我在一个项目中使用 react-translate-redux 进行国际化,但我不知道如何在组件的属性中使用翻译。具体来说,我希望将组件的标题文本国际化。

我会尝试以下,

<Button title={<Translate id="button">}>

但是Type 'Element' is not assignable to type 'string'

如何国际化标题文本?

标签: reactjsreduxreact-reduxreact-localize-redux

解决方案


如果您想使用翻译组件,您不能将其作为道具传递,您必须将其作为子组件传递并this.props.children在您的 Button Render 方法中渲染它。

如果 Button Component 是一个外部组件,您必须在 Flavor 2中使用类似这样的 prop 函数


推荐阅读