【问题标题】:React i18n, check if translation exists?React i18n,检查翻译是否存在?
【发布时间】:2023-01-25 15:28:57
【问题描述】:

有没有办法检查反应应用程序上是否存在语言环境? 就像布尔值 true/false

【问题讨论】:

    标签: internationalization react-i18next


    【解决方案1】:

    是的,您可以使用 i18n.exists() 方法检查您的语言变量是否存在:

    您可以从 useTranslation 钩子中提取 i18n

    const { t, i18n } = useTranslation();
    

    然后调用i18n.exists('my.key'),例如:

    i18n.exists("common.values.active")
    

    https://www.i18next.com/overview/api#exists

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加更多详细信息,以帮助其他人了解这如何解决所提出的问题。你可以在in the help center找到更多关于如何写出好的答案的信息。
    猜你喜欢
    • 2012-09-03
    • 1970-01-01
    • 2012-02-08
    • 2018-11-25
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    相关资源
    最近更新 更多