Extension:GoogleTranslate

A translation function calling GoogleTranslate AJAX API - based upon code from Extension:Link_Suggest

This extension will allow you to directly translate the text that you edit! This is done by calling Googles AJAX API.

Warning - the current code will, it appears, remove linebreaks, when runing in IE (internet explorer), but not in FireFox? I will look into this problem ASAP.

Installing the code
You need to cut, edit and save the following code snips, in /extensions/GoogleTranslate/, using these names:
 * GoogelTranslate.php
 * GoogelTranslate.js
 * GoogelTranslate.css

Correct these lines, to reflect your language, in the js code: // Change to your language specific texts - this should be a global in localsettings though!!

var from_to_text = "Oversæt fra/til: ";                // " Trasnlate from/to: " var translate_text = " klik her for at oversætte nu "; // " click here to translate " var close_text = " ( luk oversætter værktøjet. ) ";    // " ( close translate tool ) "

This button is needed - or rather you need to edit it to give the correct text for your language! So save the button, edit it, and give it a language specific name and change the code that loads the toolbar - this looks like:
 * add_image.src="skins/common/images/button_translate_da.png"; // you may like to put this somewhere else say in images\ ?

Please upload the button and add it below to the list of buttons!

Add this line to the localsettings.php:
 * require_once("$IP/extensions/GoogleTranslate/GoogleTranslate.php");

Buttons
Once you have created a button for your language, please add it here:
 * Danish/Dansk: [[Image:button_translate_da.png]] - reads "Translate text", save and copy to your 'skins\common\images' directory


 * Template button: [[Image:button_translate_temp.png]] - for you to download

Usage
Once installed you activate Edit on some page you want to work with. You will now see a new blank button appear: - please change this to fit your language, see below!

When you click the new buttone you will see something like this above your edit-text:



You need to change the from/to texts to read say 'ge'/'en' to translate from german to english. Also you can change the preferred translation languages in the JS code......

Put the curcer over the text that reads something like "click to translate now" and the translation will happen. (for longer texts, more sentences you will see the text flicker a bit.)

Current state of the code
This works for me, but you may run into problems. This is tested on plain text, but it may not handle texts that contain scripts, templates etc. Please let me know what does not work, or suggest solutions. :-)

The text is translated one sentence a time - this is due to a current limit in the API. In the case that the API actually do a context sensitive translation a section by section approach may give better results. Anyway this gives me a fair translation from English to Danish - and it appears to do the same for English/Swedish,Norwegian and Finish!

JavaScript
New version, does now work!!

Ideas
Please add ideas here:
 * May integrate into this: [FCKEditor]
 * Needs a preview function
 * Needs a 'translate and create new article' function

Tools to use

 * Well this may come in handy: Firebug for FireFox, debugger!
 * And this: PNG converter
 * or this: The Gimp

Code in progress
Please observe: This code does not work right not, it is a prototype! You will need to install Extension Link suggest, to get the button! (will be added as soon as I get a PNG editor :-)

The following is to-do before this will work:
 * Load and link to GoogleTranslate
 * Dropdownlists for the languages
 * See code to build dropdown box contents here - view the source: Googles dynamic translate sample


 * Default languages to be setup in localsettings.php
 * How do I get params like $wgContLang passed to the .js code?????


 * Fetch and replace the edit text (have to figure out how to)

Google AJAX API - dynamic load
See more here: Google API examples

Google translate codesnip
Sample of how to edit directly is found here: [TEX Editor]