如何在组件树之外的实用程序函数中使用react-i18next?

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

我遵循了react-i18next docs并国际化了我的React应用程序。

我使用useTranslation挂钩,这给了我“ t”对象。到目前为止,一切都很顺利,但是我在组件树之外有一些非Hook实用程序函数。

如何获得那里的翻译对象?

reactjs internationalization i18next react-i18next
1个回答
0
投票

不确定是否可以使用,但是您可以尝试这样做:

import i18n from "react-i18next";

// Then where ever you need try to this

i18n.t("target")
© www.soinside.com 2019 - 2024. All rights reserved.