0

Is it possible to change data.en.translation.test on something like this: data.language.translation.test;

I have a json file with various language objects

``

{
  "en": {
    "translation": {
      "test": "some string"
    }
  },
  "no": {
    "translation": {
      "test": "litt tekst"
    }
  }
}

`` next I have a script in html file contains object

``

window._conf = {
        widgets: {
          main: {
            theme: "dark",
            lang: "en",
            debug: true,
            i18n: "i18n.json",
          }

`` And last one file contains a function that changes H1 text depending on the language setting in window._conf object

``

var survey_face = `  <h1 id="b"></h1><table align="center" border="0" cellpadding="0" cellspacing="0"
    style="border-collapse:collapse;border-spacing:0;border:0;" width="100%">
    <tbody>
      <tr>...

``

``

 var language = window._conf.widgets.main.lang;
  function newString(newtext) {
    fetch("i18n.json")
      .then((response) => response.json())
      .then((data) => {
        newtext = data.language.translation.test;
        console.log(newtext);
        console.log();
        b.innerHTML = newtext;
      });
  }
  newString();

``

In summary I need to load the language of h1 places depending on the language set in window._conf, substituting it from the file i18n.json.

Thank You in Advance.

0 Answers0