我遵循了react-i18next docs并国际化了我的React应用程序。
我使用useTranslation挂钩,这给了我“ t”对象。到目前为止,一切都很顺利,但是我在组件树之外有一些非Hook实用程序函数。
useTranslation
如何获得那里的翻译对象?
不确定是否可以使用,但是您可以尝试这样做:
import i18n from "react-i18next"; // Then where ever you need try to this i18n.t("target")