Skip to content
Advertisement

how to fix Uncaught SyntaxError: Identifier ‘translate’ has already been declared

i can’t find solution for this bug i wrok on site web multi language but i can’t don’t know how to fix this bug

class translate{
constructor(){

    document.getElementById("fr").addEventListener('click', ()=>{
        this.translate("fr");
    });
    document.getElementById("en").addEventListener('click', ()=>{
        this.translate("en");
    });
    this.translate(localStorage.getItem("language"));
}
translate(language){
    if(language == "fr"){
        document.getElementById("myAnchor").href = "http://www.cnn.com/";
    }
    else if (language =="en"){
        document.getElementById("myAnchor").href = "http://www.google.com/";  
    }
    localStorage.setItem("language",language);
}
}
onload = new translate();

this bug

code Html and link i need to change

    <div class="contenu-space-two"> 
     <div class="row mx-0">
             <div class=" col-2">
                     <img src="./resources/_images/shopping-cart.png" class="logo-link" alt="">
             </div>
             <div class="col-lg-4 col-md-6 col-8" > 
                     <h4 class="lang" key="boutiques">Boutiques</h4>
             </div>
             <div class="col-2">
                      <a id="myAnchor" href="#"><img src="./resources/_images/arrow-link.png" class="arrow-link" alt=""></a>
             </div>
             <hr class="line_link">
    </div>

and this code language

                <div id="langContainer">
                <a class="translate" id="lang_link[en]" href="#" style="display:none"><img src="./resources/_images/flags/en.png?1595436503" title="English"></a>
                <a class="translate" id="lang_link[fr]" href="#" style="display:none"><img src="./resources/_images/flags/fr.png?1595436503" title="Fran&ccedil;ais"></a>
            </div>

Advertisement

Answer

This variable has probably already been declared. Check this js file and the others the page references.

If there are many you can try to change the name of this class.

Advertisement