程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了react-i18next 翻译不适用于传递的 Prop 元素大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决react-i18next 翻译不适用于传递的 Prop 元素?

开发过程中遇到react-i18next 翻译不适用于传递的 Prop 元素的问题如何解决?下面主要结合日常开发的经验,给出你关于react-i18next 翻译不适用于传递的 Prop 元素的解决方法建议,希望对你解决react-i18next 翻译不适用于传递的 Prop 元素有所启发或帮助;

我在我的项目中设置了一个 i18 转换器,然它对项目中的其他元素工作正常,但它似乎不适用于传递的道具元素。

这就是我使用 i18 的方式:

import { useTranslation } from 'react-i18next';
const { t } = useTranslation();

//Using the translations
{t('kitchenware')} // <-- Working fine
{t(product?.Name)} // <-- Error here
name={t(product.Name)} // <-- No error,but translations doesn't seem to work

这是我收到的错误消息

src/pages/product/index.tsx:48:33
TS2769: No overload matches this call.
  Overload 1 of 2,'(key: String | TemplateStringsArray | (String | TemplateStringsArray)[],options?: String | toptions<StringMap> | undefined): TFunctionResult',gave the following error.
    Argument of type 'String | undefined' is not assignable to parameter of type 'String | TemplateStringsArray | (String | TemplateStringsArray)[]'.
      Type 'undefined' is not assignable to type 'String | TemplateStringsArray | (String | TemplateStringsArray)[]'.
  Overload 2 of 2,DefaultValue?: String | undefined,gave the following error.
    Argument of type 'String | undefined' is not assignable to parameter of type 'String | TemplateStringsArray | (String | TemplateStringsArray)[]'.

我将确保始终传递产品值,而不是 undefined 或 null。

解决方法

我错误地引用了 i18 脚本。这在正确参后有效。

大佬总结

以上是大佬教程为你收集整理的react-i18next 翻译不适用于传递的 Prop 元素全部内容,希望文章能够帮你解决react-i18next 翻译不适用于传递的 Prop 元素所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:元素