Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

JS translation bookmarklet (See related posts)

I got this mostly working - the only thing that sucks is encoding of non-ascii characters like �, �, etc... I've tried escape(), but it's just stripped the offending character. Anyone know js and feel like fixing this?

javascript:langpair="fr|en";
  text=""+(window.getSelection?window.getSelection()
           :document.getselection?document.getSelection()
           :document.selection.createRange().text);
  if(!text)text=prompt("enter%20text%20to%20translate","");
  if(text!=null)void(window.open(
      "http://google.com/translate_t?langpair="+langpair+"&text="+text,
     "translate","scrollbars=1,resizablel=1,width=500,height=500"))

Comments on this post

cabo posts on Oct 15, 2005 at 12:24
Use encodeURIComponent (UTF-8 based), not escape (ISO 8859-1 und strange %uXXXX encoding probably unknown to Google Translate).

You need to create an account or log in to post comments to this site.


Related Posts