如何在国际化反应I18N中显示动态数据
大家好,我对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的。
BTW:I18Next的上下文功能的工作方式不同: https:/ https://www.i18next.com/translation-com./translation-com./translation-com./translation-com./translation-comle-功能/上下文
No, this is not possible.
btw: the context feature of i18next works differently: https://www.i18next.com/translation-function/context