How to translate an echo in PHP with Javascript?
one text
I have a HTML site and I made a toggle that changes the language without refreshing the page (with Javascript), I just assign an ID and that's it, as you can see here:
var strings = {
espanol: {
//PRINCIPAL//
lang: "<i class='fa-duotone fa-earth-americas fa-lg'></i> Idioma",
},
english: {
//PRINCIPAL//
lang: "<i class='fa-duotone fa-earth-americas fa-lg'></i> Language",
}
}
$( ".espanol" ).on( "click", function() {
// update to espanol
localizeStrings('espanol');
});
$( ".english" ).on( "click", function() {
// update to english
localizeStrings('english');
});
// default language
var Lang = "espanol";
// localize with default language
localizeStrings(Lang);
// update selected language
function localizeStrings(strLang) {
$(strings[strLang]).each(function(key, lang){
$.each(lang, function(id, string) {
$("#"+id).html(string);
});
});
}
To well there, but a part of my web, returns to a an echo of a PHP file.
So I have no idea how to translate it, could you help me? I am new to this.
Normal (HTML) translation:
<a class="nav-link dropdown-toggle" role="button" data-mdb-toggle="dropdown" id="lang" aria-expanded="false"></a>
PHP echo that I want to translate:
echo '{"error":-1, "msg":"<font color=#B23CFD><b>Unknown</b></font> | '.$text2.' -YES"}';
Thanks in advance.
Source