i18next / i18next-gitbook

165 stars 172 forks source link

How to use Interpolation in html attributes tag #175

Closed sadashivm closed 2 years ago

sadashivm commented 3 years ago

I'm using this library using npm module like, npm install i18next npm install loc-i18next

the above npm packages have installed in my react application but I dont want to use "npm i react-i18next".

Here is the sample code,

  1. LocalizationExample.js image image

  2. en.json image

  3. de.js image

Can you please tell me, how to pass username value to key_3 paramater?

jamuhl commented 3 years ago

https://github.com/mthh/loc-i18next#using-options-in-translation-function

jamuhl commented 3 years ago

but why not using react-i18next with react (how it is meant to be)

sadashivm commented 3 years ago

Hi Jamuhl, Thanks for reply! I checked the above reference link, still it is not working and I want to this plugin in clojure application hence I'm not using react-i18next.

Here is the my code, image image

and output is,

image

jamuhl commented 3 years ago

please create a sandbox sample for easier recreation of the problem...my current guess is that your i18n-options are not correctly formatted and can't be parsed as JSON -> but you would have to check / debug it -> or provide a sample on codesandbox so I can have a look

sadashivm commented 3 years ago

Hi jamuhl, please check below sandbox example, https://codesandbox.io/s/zen-visvesvaraya-rythp?file=/src/App.js

jamuhl commented 3 years ago

like shown here:

the options attribute as default is disabled: https://github.com/mthh/loc-i18next#initialize-the-plugin

changing useOptionsAttr: true in your code does the trick:

function updateContent() {
  const localize = locI18next.init(i18next, {
    // optionsAttr: "data-i18n-options",
    useOptionsAttr: true
  });
  localize("html");
}
sadashivm commented 3 years ago

Wow, great!!!!!!!! It is working jamuhl. Thank you so much. Have a great day :)