Skip to content

Instantly share code, notes, and snippets.

@zetxek
Last active July 2, 2022 17:08
Show Gist options
  • Save zetxek/2c0cb86828f3f3a4e9ce6c6369e42c6e to your computer and use it in GitHub Desktop.
Save zetxek/2c0cb86828f3f3a4e9ce6c6369e42c6e to your computer and use it in GitHub Desktop.
Google translate bookmarklet code - to load a google translate bar.
// create it in your browser by copying the rest of the script - and appending the "address" with "javascript: ", and then paste the code
try {
console.log("starting, inserting script");
languages = "en,es,da";
o = document.createElement("scri" + "pt");
o.setAttribute(
"src",
"https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"
);
o.setAttribute("type", "text/javascript");
document.body.appendChild(o);
v = document.body.insertBefore(
document.createElement("div"),
document.body.firstChild
);
v.id = "google_translate_element";
p = document.createElement("scri" + "pt");
p.text =
"function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'auto', includedLanguages: '"+languages+"', autoDisplay: true, layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');}";
p.setAttribute("type", "text/javascript");
document.body.appendChild(p);
console.log("script inserted");
} catch (e) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment