Extension:Live Translate

Live Translate is a simple extension that allows live translation of wiki pages using Google Translate or (as of version 1.1) Microsoft Translator. It also enables you to define a "dictionary" of certain words or phrases and their translations; any word or phrase in the original text found in the "dictionary" will be translated using that dictionary, instead of using the Google/Microsoft translation service.

Feature overview

 * Live translation of page contents using Google Translate.
 * Ability to define translations of special words in-wiki or in a remote file in either a special wiki format or TMX. These are then left alone by Google Translate.
 * Support for multiple translation memories which can be added and managed via a GUI.
 * Usage of the MediaWiki Resource Loader when available with backward support for MW 1.16.x.

Download
You can find the current version of Live Translate on the Google Code download page, as well as a list of legacy downloads.

You can also get the code directly from Git. To get the latest version, call the following:

Installation
Once you have downloaded the code, place the LiveTranslate directory within your MediaWiki 'extensions' directory. Then add the following code to your LocalSettings.php file:

After this you need to run MediaWiki's update script, which can be found at /maintenance/update.php. You also need to run this when upgrading to version 0.4 or above from an older version.

After doing this, you have installed the extension. To be able to use it in a meaningful way, you also need to take care of some configuration:

Configuration
Configuration of Live Translate is done by adding simple PHP statements to your LocalSettings.php file. These statements need to be placed AFTER the inclusion of Live Translate. The options are listed below and their default is set in the Live Translate settings file. You should NOT modify the settings file, but can have a look at it to get an idea of how to use the settings, in case the below descriptions do not suffice.

Available languages
You have to specify which languages users should be able to translate to. This is done by adding language codes to. By default it contains only your wiki's main language (as specified by  in LocalSettings.php). You add languages to it as follows:

If there are no languages available other than the current language of the page, then the translation control will not show up.

Translation service
As of Live Translate 1.1, you can make use of either the Google Translate or Micorosft Translation services. You can specify the service with the following setting:

Available values are  and. The default is.

Google API key
To be able to actually use Google Translate, you need to get an API key and add it to your LocalSettings.php file AFTER the inclusion of the extension.

Microsoft App ID
To be able to use the Microsoft Translation service, you need to get an App Id and add it to your LocalSettings.php file AFTER the inclusion of the extension.

Permissions
In order to edit the list of translation memories, you need the 'managetms' permission. By default only sysops have this permission.

The translation control
Live Translate adds a "Translate" button to the top right-hand corner of wiki pages, together with a dropdown menu that allows you to select the target language. Hitting the "Translate" button will cause the text in the wiki page to be translated to the selected destination language within the browser (it will not modify the original source text in any way). The source language will be assumed to be the wiki's main language, unless the wiki page's name ends with a "/" and then a language code, e.g., "Main Page/de" - if that is the case, the wiki page's language will be assumed to be the one that corresponds to that language code.

After a user hits the "Translate" button, another button, "Show original", will appear, which if pressed will return the display to its original language.

Managing translation dictionaries


Since version 0.4, you can define multiple translation memories, which can be either local (in a wiki page) or remote (anything in a file), and can be in any of the supported translation memory formats. You can add new memories and manage existing ones via Special:LiveTranslate. By default this page can only by accessed by administrators, but this can be changed, see the configuration section. Saving the translation memories will result into them either getting imported or updated (if they already exist).

Explanation of the interface fields:


 * Location: For local memories, this should be the name of the page. For remote memories, it should be the full path to the file.
 * Type: The format of the translation memory. See "defining a translation dictionary".
 * Local: Are the translations part of a wiki page or not?
 * remove: Check this to remove the translation memory from Live Translate. The memory itself (file or wiki page) will continue to exist, but will stop being used in translations done via the Live Translate control.

Protecting local translation memories can be done using the native MediaWiki page protection functionality.

Defining a translation dictionary
Currently Live Translate supports 2 translation memory formats.

Live Translate format
This format was created specially for this extension and easy use on wikis. It's a simple CSV (comma-separated values) style format, in which the first row contains the set of relevant language codes, and the successive ones the translations. An example would be:

en, nl, de Hello world, Hallo wereld, Hallo welt Awesome, Geweldig, Große

The format supports defining synonyms. You can add them using the | sign as delimiter. For example, if you want "fantastic" to be translated the same as "awesome", the above dictionary would change to:

en, nl, de Hello world, Hallo wereld, Hallo welt Awesome|fantastic, Geweldig, Große

This means that "fantastic" will be handled exactly the same as "Awesome" when translating from English to one of the other languages. When translating to English, the first word in the synonym list, in this case "Awesome", will be used. So translating the Dutch "Geweldig" to English will result in "Awesome".

Translation Memory eXchange
This is a commonly used standard for translation memories. See the Wikipedia article.

Optional disclaimer
Google translate produces a draft translation which can contain errors of grammar. The translation can be incomplete or contain mis-translations through mis-identification of the correct context of a translated word. This extension is best suited to translating texts to the reader's language (for which it was designed) or to produce a first draft of a translation which is then revised by a human translator before being published. It is not suited to be used to produce many language versions of an original for publication or onward distribution.

An optional disclaimer is under design that would add a disclaimer concerning the quality of the draft translation produced, to alert potential users to the danger of publishing the unedited translations.

Version
This is a copy of the release notes file on Git, which might be more up-to-date than this page.

Version 1.2.1
2011-09-12


 * Fixed Internet Explorer compatibility issue.

Version 1.2
2011-08-14


 * Rewrote translation control JavaScript to a jQuery plugin.
 * Added caching layer utilizing memory and LocalStorage when available to speed up local translations.
 * Added API module to query translation memories.
 * Added i18n alias file.
 * Added TMX admin user rights group.

Version 1.1.1
2011-06-22


 * Fixed Internet Explorer compatibility issue.
 * Fixed bug in Microsoft transltion script for MW < 1.17.
 * Made Microsoft transltion script more robust by adding timeouts.

Version 1.1
2011-06-16


 * Added support for the Microsoft Translation service.
 * Added support for comments in the LiveTranslate TMX format.
 * Added debug messages in the JavaScript that can be logged by setting $egLiveTranslateDebugJS to true.

Version 1.0.1
2011-05-27


 * Added option (on by default) to store insignificant translations.
 * Tweaked the LTF parser to allow specifying a word that should never be translated.

Version 1.0
2011-05-26


 * Fixed bug in the API.
 * Fixed some JavaScript issues causing problems for IE users.
 * Added missing right declaration.

Version 0.6
2011-04-21


 * Added settings to specify per-namespace if the translation control should be shown or not.
 * Use of FormatJson::encode instead of josn_encode for compatibility with PHP5 < 5.2.

Version 0.5
2011-01-16


 * Modified the LT API to work with batches, so translation doesn't break for big translation memories.
 * Fixed regex escaping issue that caused translations to stop when encountering certain characters in special words.

Version 0.4
2011-01-14


 * Added support for multiple translation memories.
 * Added Special:LiveTranslate to manage the translation memories that should be used.
 * Added support for remote translation memories.
 * Added support for the Translation Memory eXchange (TMX) format.
 * Added Google branding, which is required when using the Google Translate API.
 * https://code.google.com/apis/language/translate/v1/getting_started.html#getBranding


 * Improved translation memory insertion into the database.
 * Added better tracking of translation memory sizes and language counts.

Version 0.3
2011-01-07


 * Added compatibility with IE8.
 * Fixed issue with trim-prevention, causing |-signs to semi-randomly get inserted into translated text.
 * Only show the translation control when an API key is provided.

Version 0.2
2010-12-24


 * Fixed installation compatibility issue with MW 1.16.
 * Fixed display of translation control to only happen on existing pages.
 * Fixed issues with inserting notranslatre tags into the page source.

Version 0.1
2010-12-22


 * Added simple translation interface to the right top of articles.
 * Implemented translation via the Google Translate API.
 * Added dictionary for special words with synonyms support.

Internationalization
Live Translate is fully internationalized. Translation of Live Translate messages is done through translatewiki.net. The translation for this extension can be found here. To add language values or change existing ones, you should create an account on translatewiki.net, then request permission from the administrators to translate a certain language or languages on this page (this is a very simple process). Once you have permission for a given language, you can log in and add or edit whatever messages you want to in that language.

Roadmap
These features would be nice to ad at some point:


 * Utilize HTML5 localStorage when available to store the TMX data relevant to the user. For TMXs with a few thousands translations, this would eliminate several big HTTP requests that need to happen before each translation, thus providing a significant speedup. Invalidation can be done by requesting a simple hash or timestamp of the last TMX update via some new API module.

Authors
Live Translate has been written by Jeroen De Dauw as WikiWorks consultant for Texas Instruments.