How do I pass a translated string to another component in react-jhipster?

时间:2019-04-08 13:31:21

标签: reactjs internationalization translation jhipster

I can use the Translation component (from react-jhipster) when i want to add a translated string in a component:

<p><Translation contentKey="my.key">Some text</Translation></p>

But if I want to pass a translated string to another component, how would I do that? Like:

<MyComponent text={{translate("my.key")}} />

1 个答案:

答案 0 :(得分:1)

正如您在评论中所说,您正在使用react-jhipster库。

从我得到的信息中,您可以从translate (contentKey: string, interpolate?: any, children?: string)导入react-jhipster函数。

尝试:import {translate} from 'react-jhipster'

  

来源:https://github.com/jhipster/react-jhipster/blob/master/src/language/translate.tsx


您不需要总是像道具那样传递它,也可以在组件的主体中使用它。