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")}} />
答案 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
您不需要总是像道具那样传递它,也可以在组件的主体中使用它。