Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda