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 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 3>Milkshake|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 4>Special:MyLanguage/Extension:VisualEditor|VisualEditor and 5>Special:MyLanguage/Extension:UniversalLanguageSelector|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 <tvar|1></> configuration key is used to list these subdirectories. Here's an example from the <tvar|1>VisualEditor</> extension for MediaWiki:

You add new messages to the English "<tvar|1>en</>" messages file <tvar|2> </> and document them in the message documentation file with the special pseudo-language code "<tvar|3>qqq</>" – <tvar|4> </>. See also: 1>Special:MyLanguage/Localisation#Adding new messages</>|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 (<tvar|1>en</>) and message documentation (<tvar|2>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 <tvar|1>translatewiki.net</>. Message documentation can be edited on <tvar|1>translatewiki.net</>, and documentation editors are inserted to the <tvar|2>qqq.json</> file automatically as well.
 * message-documentation
 * This is the pseudo-language code for storing the message documentation.

For MediaWiki this is always <tvar|1>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 (<tvar|1> </>).

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 (<tvar|1> </> and not <tvar|2> </>). 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 <tvar|1> </> and not <tvar|2> </>.

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 (<tvar|1>qqq</>) are in the same file: <tvar|2>ExtensionName.i18n.php</>, usually in the main directory of the extension.

To migrate from PHP to JSON use the 1>Special:MyLanguage/Manual:GenerateJsonI18n.php</>|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.