Localisation file format

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 it is suggested to 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 translation. 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 extension that want to be less dependent on MediaWiki, such as VisualEditor and UniversalLanguageSelector.

File location
The files are stored under languages/i18n directory in core MediaWiki. In extensions they are usually under the i18n directory.

In extensions with a large number of messages more directories can be added under i18n for maintainability. The $wgMessagesDirs variable is used to list these directories; here's an example from the VisualEditor extension:

The *.i18n.php files load the messages.

New messages are added to the English messages file (en.json) and to the special message documentation file (qqq.json). See also: Localisation

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 is 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 on 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.