当我想在组件中添加翻译的字符串时,我可以使用翻译组件(来自react-jhipster):
<p><Translation contentKey="my.key">Some text</Translation></p>
但是,如果我想将翻译后的字符串传递给另一个组件,我该怎么做?喜欢:
<MyComponent text={{translate("my.key")}} />
正如您在评论中所说,您正在使用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
而且你不需要总是像道具一样传递它,你也可以在组件的身体中使用它。