2013年2月20日 星期三

How to Create a Bookmarklet for a Translation Engine


To create a bookmarklet for a translation engine, follow these steps:
Go to your translation engine site. Set the appropriate options such as source and target languages. Enter a dummy Web address to be translated, e.g. "DUMMY_ADDRESS" 
Run the translation
Copy the Web address of the translation page to a text editor. Some translation engine uses frames; in that case, right click (ctrl+click on Mac OS X) the frame of the translated text and choose This Frame | Show Only This Frame. 
In the text editor, find the dummy address. 

If the dummy address is somewhere in the middle, replace it with "+escape(location.href)+". Append "; to the end of the line. Add javascript:location.href=" to the begining of the line. 
 For example: 
http://translate.google.com/translate?u=DUMMY_ADDRESS&langpair=en%7Cfr
 becomes 
javascript:location.href="http://translate.google.com/translate?u="+escape(location.href)+"&langpair=en%7Cfr";

If the dummy address is at the end, replace it with "+escape(location.href); and add javascript:location.href=" to the begining of the line. For example: 
http://translate.google.com/translate?langpair=en%7Cfr&u=DUMMY_ADDRESS
 becomes 
javascript:location.href="http://translate.google.com/translate?langpair=en%7Cfr&u="+escape(location.href);

If the dummy address is nowhere to be found, then the settings are passed "in the background" and you cannot create a bookmarklet for it.
Create a bookmark and set its location to the text in your text editor.

沒有留言: