Extension:Live Translate

The Live Translate extension allows users to do live translation of wiki pages using either Google Translate or 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 either Google's or Microsoft's translation services.
 * "Auto-translation" so that, if a user translates a page into a certain language, or has their language preference set to a language other than the wiki's, subsequent pages will automatically get translated to that other language.
 * 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.

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.

Available languages
You have to specify which languages users will 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
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 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 Client ID and secret
To be able to use the Microsoft Translation service, you need to get a Microsoft Client ID and "secret"; you will need to get a Bing account first, if you don't already have one. Once you get those values, add lines like the following 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.

Auto-translation
By default, Live Translate will automatically translate pages into a specific language, if the user has set that language in their user preferences, or if they have previously translated a page into that language. You can avoid that by adding the following to LocalSettings.php, after the inclusion of the extension:

Avoiding auto-translation may be useful if you have a high-traffic wiki, and you want to make sure that your number of translated bytes per month does not exceed the allowed quota for your account.

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


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
Live Translate supports two 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
Automated translation services produce text which can contain errors of grammar. The translation can be incomplete, or can 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 text for publication or onward distribution.

Version 1.3
2013-07-02


 * Update for new Microsoft translation API.
 * Added auto-translation feature.

Version 1.2.3
2011-11-15


 * Added action-managetms message.
 * Fixed JavaScript dependency issue causing the extension to break on MediaWiki 1.19 and later.
 * JavaScript tweaks.

Version 1.2.2
2011-09-15


 * Fixed script loading issue occurring when ResourceLoader debugging is off.

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 add 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 was written by Jeroen De Dauw as a WikiWorks consultant for Texas Instruments. Additional work was done by Nischay Nahata and Yaron Koren, again as WikiWorks consultants for Texas Instruments.