Skip to content

Instantly share code, notes, and snippets.

@nootanghimire
Created December 6, 2015 16:20
Show Gist options
  • Save nootanghimire/057304932c6a18e94e4d to your computer and use it in GitHub Desktop.
Save nootanghimire/057304932c6a18e94e4d to your computer and use it in GitHub Desktop.
var url = "https://mozilla-nepal.org/translation-helper-pootle/translate.php?string=";
document.onclick = function (e) {
var elem, evt = e ? e:event;
if (evt.srcElement) elem = evt.srcElement;
else if (evt.target) elem = evt.target;
if(elem.nodeName == "INPUT" || elem.nodeName == "TEXTAREA") {
var s = (elem.getAttribute("id"));
s = s.split('_')[1];
var strUntranslated = document.getElementById("msgset_"+s+"_singular").textContent;
//console.log(strUntranslated);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
if (elem.value==""){
elem.value=xhttp.responseText;
}
}
}
//text = text.replace(/&/g, "");
xhttp.open("GET", url+strUntranslated, true);
console.log(url+strUntranslated);
xhttp.send();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment