Help:Extension:Translate/Translation aids

Translation aids (or helpers) are little modules that provide helpful and necessary information for the translator when translating. Different aids can provide suggestions from translation memory and machine translation, documentation about the message or even such a basic thing as the message definition – the text that needs to be translated.

There is some overlap between the data what is provided by Message Collection and the aids, but the rule of thumb is that Message Collection only provides information that is absolutely needed to present the list of messages: definition, translation, status of translation, last translator (because one can only review translations made by someone else) etc.

Translate comes with many aid classes. Each class that extends the TranslationAid class only needs to implement one method called. It should return the information in structured format (nested arrays). These modules can be called either directly from PHP and also via the WebAPI.

How to use translation aids inside MediaWiki
Simple example to get the message documentation of a message, if available.

How to use translations aids API
As already seen above, translation aids are available via WebAPI which is using the MediaWiki WebAPI framework. Getting translation aids is as simple as doing HTTP GET for the url http://translatewiki.net/w/api.php?action=translationaids&title=MediaWiki%3AJan%2Fde. It provides various different formats, but json and xml are the most popular ones. This API does not need authentication, but some translation aids like "inotherlanguages" uses user preferences to determine which languages to use. To use that aid you shoud log in first as described in the MediaWiki WebAPI documentation.

The returned data should look like this (shown in pretty json format):

Every requested aid is guaranteed to have key here (until the request fails miserably), but while we use exceptions in the PHP side, in JavaScript side each aid may have the key "error" set with value as internal error message. You can see example of this above with. It signals an error that it cannot display a diff, because there have been no changes to the definition since last translation.

JavaScript example
Here is a same thing for JavaScript. By default the api returns all aids, but you can request specific ones with the  param. In the example we are using jsonp to work around cross site request limitations. Be aware that you cannot execute any write actions with jsonp, so if you are using this API from JavaScript you will need a proxy, run the script on the same host or load a little helper (not yet implemented) from the target site.

Naming conventions
Each translation aid has a unique string identifier. Identifiers should avoid special characters, especially those which are not valid in JavaScript identifiers, like - and *.

The array that is returned by each translation aid is up to the developer, but should follow general recommendations:

If only one text value is returned, it should use field key value. Language should be provided in field language. Users of this data should ensure that in HTML and elsewhere the text is tagged properly with the provided language and directionality (not provided here). If there is HTML output, it should be available with key html. Examples of this are message documentation and diffs.

Various kinds of translation suggestions like machine translation and translation memories should use these keys when they make sense:
 * source, source_language and target (target language is implicitly the same as the language of the translation)
 * server: identifier of the service used
 * quality: value in range [0,1], higher value means that the quality of the suggestions is very good.