如何将翻译后的字符串传递给react-jhipster中的另一个组件?

问题描述 投票:2回答:1

当我想在组件中添加翻译的字符串时,我可以使用翻译组件(来自react-jhipster):

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

但是,如果我想将翻译后的字符串传递给另一个组件,我该怎么做?喜欢:

<MyComponent text={{translate("my.key")}} />
reactjs internationalization translation jhipster
1个回答
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


而且你不需要总是像道具一样传递它,你也可以在组件的身体中使用它。

© www.soinside.com 2019 - 2024. All rights reserved.