Search code examples
reactjsi18nextreact-i18next

i18next interpolation on nested data not displaying content of variable


I am using i18next library with React Js:
"i18next": "^20.4.0" :

Using the library ref docs :
https://www.i18next.com/translation-function/objects-and-arrays

I have put the content in public/locale/translation File :

"SomKey": {
    "title": "Your payment is due soon {{paymentDueDate}}",
    "detail": "Please pay your bill on or before {{paymentDueDate}}.",
  },

In my code I am accessing as :

i18next.t("SomKey", { 
                    returnObjects: true, 
                    paymentDueDate:"24-12-2022"
                });

But its displaying the Brackets as it is and not the date

Notification Image


Solution

  • That i18next version is using the legacy formatting… You need to define a format function: https://www.i18next.com/translation-function/formatting#legacy-format-function-i18next-less-than-21.3.0