New MediaWiki extension: Live Translate

I’m happy to announce the release of a new MediaWiki extension I’ve been working on over the past two weeks. It’s titled Live Translate and allows live page translation via the Google Translate API. 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 Google Translate.

The main features are:

  • Live translation of page contents using Google Translate.
  • Ability to define translations of special words in-wiki that will then be left alone by Google Translate.

Some screenshots

A wiki page with the translation control of the Live Translate extension at the right top corner:

A wiki page with the translation control of the Live Translate extension at the right top corner.

The same page after translating it to Dutch:

The same page after translating it to Dutch

The dictionary page briefly summarizing how many words and languages it contains:

The dictionary page briefly summarizing how many words and languages it contains.

Editing the special words dictionary works just like editing any other page:

Editing the special words dictionary works just like editing any other page.

Funding

I created this extension as WikiWorks consultant for Texas Instruments. Thanks to TI for funding this and allowing licensing under the GNU GPL.

WikiWorks, MediaWiki consulting

Points of interest

For me the most interesting part of creating this extension was figuring out how to walk through the page DOM and send only the actual text to the Google Translate API using JavaScript (and jQuery). This step was needed because the GT API limits translation requests to 500 characters, so it’s not definitely possible to send the whole page. It took me a while to figure this out, and I still think it’s a rather lame limit, as it leads to loss of context, and thus worse translations.

The rest of the extension is rather simple and does not contain anything I haven’t done before. The special words dictionary is stored in a simple db table (fields: word id, word text, word language and word primary) and can be accessed via 2 API modules. One is to query a list of the special words that are defined for a language, the other is to get translations of a set of special words from one language to the other. When you request your first translation of a page, the first API module is hit and the result is used to insert notranslate spans, which make Google Translate ignore stuff, around the special words. After that the other module is hit, the special words are replaced by their translations, and finally the script sends a ton of requests to the GT API.

Ah, and not to forgot, I used a XOR. I kid you not, source code or it didn’t happen (see the last function).

State and future

Live Translate is currently at version 0.2 and contains all the features initially requested by TI. It appears to be stable, and ready for production usage. Of course, if bugs pop up, they will be addressed and a new minor version will be released. A cool new feature I’ve been considering, and might add at some point, is having __LIVETRANSLATE__ and __NOLIVETRANSLATE__ magic words, that allow per-page showing or hiding of the translation control. Yaron suggested also having a per-namespace setting. If you have some cool new features in mind, feel free to suggest them on the Live Translate discussion page (where you also can ask for support and point out bugs). If you want to fund any new functionality, please contact WikiWorks.

You can obtain the latest version of Live Translate here.

I’m happy to announce the release of a new MediaWiki extension I’ve been working on over the past two weeks.

3 thoughts on “New MediaWiki extension: Live Translate”

  1. How can I use this feature on ordinar wikipedia? For example on ukrainian wiki?

    P.S.Live translate is TM of Microsoft, as I remember.

  2. In order to use a MediaWiki extension it needs to be installed on the wiki where you want to use it. So you cannot use Live Translate on Wikipedia, or any other WMF wiki.

    Thanks for the TM hint.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.