Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda