【问题标题】:How can I use translations in a component title?如何在组件标题中使用翻译?
【发布时间】:2019-11-03 18:28:25
【问题描述】:

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

我会尝试以下,

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

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

如何国际化标题文本?

【问题讨论】:

标签: reactjs redux react-redux react-localize-redux


【解决方案1】:

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

如果 Button 组件是一个外部组件,你必须使用类似 Flavor 2 中 this 的 prop 函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2012-10-11
    相关资源
    最近更新 更多