Localisation file format/en

All messages used in MediaWiki are defined in a messages file.

There are two types of message files in MediaWiki: JSON and PHP. As of April 2014, core MediaWiki and most of the maintained extensions were migrated to the JSON format. For more information about the migration to JSON see Requests for comment/Localisation format. Both formats are supported, but you should use JSON for all new development. Support for PHP will be removed in the future; this will be announced separately.

JSON
Starting from late 2013 a new file format for messages was introduced: JSON. This is plain JSON, familiar as a common generic data storage format. Every key in it is a message key, and the value is the message text. In addition, the special  key is used to store information about the translation, such as the translation authors.

Using JSON makes the localisation files more secure because it's not executable. It is also compatible with jquery.i18n, a JavaScript library developed as part of Project Milkshake, which provides MediaWiki-like frontend localisation capabilities and is used by some extensions that want to be less dependent on MediaWiki, such as VisualEditor and UniversalLanguageSelector.

Because the wider suite of internationalisation and localisation tools were called "Project Milkshake", some people call this format "banana".

File location
In MediaWiki core, localisation files are placed in the  directory. MediaWiki extensions usually place theirs in an  subdirectory. If a large number of messages exist within a project, one may want to split these into two or more topical subdirectories for maintainability. In MediaWiki context, the configuration key is used to list these subdirectories. Here's an example from the VisualEditor extension for MediaWiki:

You add new messages to the English "en" messages file  and document them in the message documentation file with the special pseudo-language code "qqq" –. See also: Localisation#Adding new messages.

Metadata
Currently the following metadata fields are used in the files:


 * authors
 * A JSON list of the authors of the messages. For English (en) and message documentation (qqq) these are added manually when the messages file is edited. For all other languages this is inserted automatically when the message file is exported from translatewiki.net. Message documentation can be edited on translatewiki.net, and documentation editors are inserted to the qqq.json automatically as well.


 * message-documentation
 * This is the pseudo-language code for storing the message documentation. For MediaWiki this is always qqq. (This appears in some extensions, but it's not actually processed in any way. It's not mandatory.)

Conventions
Special characters like line breaks are escaped.

Unicode characters that represent letters in different alphabets are stored as real characters and not as character codes, because these files are sometimes read by people and because this makes the files smaller ( and not  ). In any case, developers have few reasons to edit messages in any languages except English, because these are usually edited through translatewiki.net.

HTML code is not escaped either, so  and not.

The JSON files are indented using tabs.

PHP
The older localisation file format is PHP. This is essentially a PHP array with all the messages. In core MediaWiki each language resides in its own file in the languages/message directory of the MediaWiki source code. In the extensions all the languages and the message documentation (qqq) are in the same file: ExtensionName.i18n.php, usually in the main directory of the extension.

To migrate from PHP to JSON use the generateJsonI18n.php script. It will move the messages to JSON files and replace the text of the PHP file with a shim that points to the JSON files. This boilerplate code is needed for backwards compatibility with MediaWiki 1.19. It is not used in new extensions that do not require MediaWiki 1.19 compatibility.