[英]How to show dynamic data in internationalization react i18n
Hey guys I have a question regarding react i18n.嘿伙计们,我有一个关于 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并且action-history-description
字符串看起来像这样
"{{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.然后 i18n 完成剩下的工作。 So if I have the actionData.status
its value is shown.所以如果我有actionData.status
它的值就会显示出来。 If not then context and so on.如果不是,那么上下文等等。 Is there any way to do this?有没有办法做到这一点?
No, this is not possible.不,这是不可能的。 btw: the context feature of i18next works differently: https://www.i18next.com/translation-function/context顺便说一句:i18next 的上下文功能不同: https ://www.i18next.com/translation-function/context
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.