简体   繁体   中英

How to show dynamic data in internationalization react i18n

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM