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 code works in Firefox, Opera and Chrome. But it does not work for IE (Internet explorer). When running in IE, the current code removes linebreaks. I will look into this problem ASAP.

Improvements
Please could someone look into how to make this work in conjunction to say Template:Languages/Lang Extension:Duplicator etc.

Installing the code
You need to cut, edit and save the following code snips, in /extensions/GoogleTranslate/, using these names:
 * GoogleTranslate.php
 * GoogleTranslate.js
 * GoogleTranslate.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 button 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 cursor 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.)

PHP
This is where the GoogleApi is actually loaded....

JavaScript
New version, does now work for Firefox - see further here: Google translate problems

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]