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.

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

Usage
Onece 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:



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. :-)

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]