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.
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 dictionary page briefly summarizing how many words and languages it contains:
Editing the special words dictionary works just like editing any other page:
I created this extension as WikiWorks consultant for Texas Instruments. Thanks to TI for funding this and allowing licensing under the GNU GPL.
Points of interest
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.