Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
calling an json object by adding a variable to the path

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!