Requests for comment/Move i18n data into JSON

From mediawiki.org
Request for comment (RFC)
Move i18n data into JSON
Component Localisation
Creation date
Author(s) Legoktm, Siebrand, James F.
Document status in draft
See Phabricator.

Let's move the rest of the i18n data in extensions into JSON. We previously migrated i18n messages.

Background[edit]

We currently have a lot of i18n data still in PHP:

// Namespaces
$namespaceNames['en'] = [
	828 => 'Module',
	829 => 'Module_talk',
];

// Magic words
/** English (English) */
$magicWords['en'] = [
	'invoke' => [ 0, 'invoke' ],
];

// Special pages
/** English (English) */
$specialPageAliases['en'] = [
	'MassMessage' => [ 'MassMessage' ],
];

There's plenty of more (see languages/messages/) in core, but for this proposal we'll focus on the three types that extensions typically use: magic words, special pages, and namespaces.

Problem[edit]

Keeping i18n data in an executable file format is bad. We migrated away from this once with moving messages into JSON files, allowing us to build tools that can check the validty of those files (grunt-banana-checker) without having to execute arbitrary, potentially untrusted code.

Proposal[edit]

We currently have a JSON file for each language in i18n. We'll extend this format to add the extra data in:

{
	"@magic": {
		"invoke": [ 0, "invoke" ]
	},
	"@namespaces": {
		"828": "Module",
		"829": "Module_talk"
	},
	"@specialaliases": {
		"MassMessage": [ "MassMessage" ]
	},
}

Currently the prefix @ key is used by the @metadata key which contains authorship information. Since LocalisationCache already ignores @ keys, this should be fully backwards compatible. As we did last time, a shim would be provided for extensions that want to continue supporting old versions of MediaWiki core.

Implementation[edit]

  • Add support for this in MediaWiki core
  • Write script to automatically convert extension data to JSON
  • Convert a few extensions and see how it works in Wikimedia production
  • Bonus points: Re-add support to translatewiki.net to translate this data on-wiki.

See also[edit]