如何在国际化反应I18N中显示动态数据

发布于 2025-01-31 09:14:22 字数 644 浏览 3 评论 0原文

大家好,我对React I18N有疑问。我有一个这样的场景,我要翻译这样的翻译

const context = history?.actionData?.status ||
  history?.context ||
  history.action ||
  "N/A";

t("action-history-description", {...history, context)

,而Action-History-description字符串看起来像这样,

"{{context}} - ({{actionData.user.name}} - {{actionData.user.phone"

我想做的就是在字符串内移动上下文条件。因此,字符串应该看起来像这样

"{{actionData.status || context || action || 'N/A'}} - ({{actionData.user.name}} - {{actionData.user.phone"

,然后I18N完成了其余的工作。因此,如果我有actiondata.status其值。如果不是这样,则上下文等等。有什么办法做到这一点吗?

Hey guys I have a question regarding react i18n. I have a scenario where I'm translating like this

const context = history?.actionData?.status ||
  history?.context ||
  history.action ||
  "N/A";

t("action-history-description", {...history, context)

and the action-history-description string looks like this

"{{context}} - ({{actionData.user.name}} - {{actionData.user.phone"

What I want to do is move the context condition inside the string. so the string should look like this

"{{actionData.status || context || action || 'N/A'}} - ({{actionData.user.name}} - {{actionData.user.phone"

and then i18n does the rest of the job. So if I have the actionData.status its value is shown. If not then context and so on. Is there any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春有你 2025-02-07 09:14:22

No, this is not possible.
btw: the context feature of i18next works differently: https://www.i18next.com/translation-function/context

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文