Can you help me update my Chrome search engine for Google Translate?
April 14, 2019 4:44 PM   Subscribe

I had this Chrome search engine from years and years ago. It worked great until something changed a while back (possibly the Google Translate URL parameters), and now no dice. I've been getting by just updating the 3 arguments in a bookmark for the search URL, but can you help me update my search engine instead?

This is the code for my Chrome search engine, which was initially a Firefox bookmarklet and used to work just fine in Chrome as well.
And this is the URL I end up using, just replacing the three arguments ("es," "en," and "guia de discusion") with 1. whatever language I'm translating from, 2. the language I'm translating to, and 3. the phrase to be translated
This URL works as well (it's what's generated by the Google Translate web app), and doesn't have an extra "guia":
Can you suggest how I might put these together and update the bookmarklet/search engine code so it works again, knowing that the URLs above are now what works?
posted by limeonaire to Computers & Internet (3 answers total)
Your bookmarklet above cuts off at:


... almost certainly the next character is < which is the beginning of markup and is causing it to get cut off when it's interpreted as the beginning of an html tag. Try running your bookmarklet code through an encoder such as this one and re-posting it.
posted by axiom at 5:11 PM on April 14 [1 favorite]

Here's a bookmarklet to do translation. It doesn't work with the Chrome browser search mechanism b/c javascript is entirely disabled there (this is why your above bookmarklet stopped working; the change to the translate URL formatting is incidental, no amount of rewriting that is going to cause chrome to allow javascript there).

query = prompt("Translate",window.getSelection());
if (!query || query.trim().length == 0) {
  alert("Nothing to do!");
} else {
  args = query.split(" ");
  src = "auto";
  trg = "en";
  if (args[0].indexOf(",") > 0) {
    lngCodes = args.shift().split(",");
    if (langs.indexOf(lngCodes[0]) >= 0 && langs.indexOf(lngCodes[1]) >= 0) {
      src = lngCodes[0];
      trg = lngCodes[1];
  trans = ""+src+"&tl="+trg;
  comma = "&text=";
  for (i = 0; i < args.length; i++) {
    comma=" ";

Mefi won't let me make a "javascript:" link (for security reasons), so you'll have to cut-and-paste that code into a bookmarklet creator like this one. Just paste it in, name it (i.e., replace "this link" with something like "Translate"), then hit "convert to bookmarklet". Then drag the bookmarklet link (in blue) to your browser toolbar.

The way this bookmarklet works is that you can highlight some text on the page and then click the bookmarklet button in your browser toolbar. It will prompt you with a text input (which will contain the highlighted text, if any). You can just hit OK (after putting some text in, if you didn't highlight anything before clicking the bookmarklet) and it will attempt to have the translation service guess the source language (and will translate to english). Alternately you can edit the contents of the box, prepending it with a comma-separated pair of language codes which will specify the source and target languages respectively. So "es,fr hola mundo" will result in "salut monde" for example.
posted by axiom at 6:47 PM on April 14 [1 favorite]

Ah good call, here's the non-cut-off version.


Edit: It still got cut off, because it's Javascript. So never mind.

But yeah, I thought I'd vaguely read something about Javascript not being allowed for Chrome search engines anymore, so maybe it doesn't matter. For the meantime, for expediency's sake, I might just switch to a URL that only requires one argument and defaults to Spanish, since that's what I translate from the most. I'm interested in other suggestions!
posted by limeonaire at 8:41 PM on April 14

« Older My house is built like a tank that I can't drill...   |   Do you love your wedge sleep pillow? Newer »

You are not logged in, either login or create an account to post comments