A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format below:

Requests for comment/Localisation format - MediaWiki

This is an RfC on a JSON based localisation format and structure for MediaWiki core and extensions, based on the work to create jQuery.i18n. There will be no loss of internationalisation or localisation functionality in this change.

The current MediaWiki localisation files are based on PHP arrays. Having PHP arrays makes the localisation files not directly usable in JavaScript, which will be a follow-up stage to this change. Having JSON as the MediaWiki file format will make it easier to integrate modularly-developed functionality into MediaWiki, while preserving all the rich internationalisation features MediaWiki currently enjoys.

The largest i18n files in extensions currently contain localisations for 200 or more languages, have a size in the megabytes, and have several tens of thousands lines (for example WikimediaCCLicenseTexts.i18n.php is 3.8 MiB and over 18,000 lines, and UploadWizard.i18n.php is 3.4 MiB and over 32,000 lines). These large files are hard to edit for developers altering existing English messages and adding new ones, and slow to process for MediaWiki and others. A change in one translation in an extension could for example no longer trigger a re-cache of all languages any more, as we can track timestamps per language after this change. This benefit applies to MediaWiki core as well as to translatewiki.net. While handling JSON may be slower than using PHP (we have no benchmarks on this), overall this change can improve performance by avoiding loading unnecessary data, as data for each language is held in a separate file.

Additionally, using executable PHP files is a potential security risk. Loading the messages for translation at translatewiki.net and any other kind of manipulation is icky.

Requirements are at least the following:

  1. The scope of this RfC is limited to $messages.
  2. The messages should be stored in a non-executable UTF-8 file format.
  3. MediaWiki core and individual extensions should be able to have multiple groups of messages, located in an advised standard structure (for example, i18n/[modulename]/langcode.json).
  4. All current MediaWiki i18n features must keep working.
  5. The current extension localisation format should keep working ($wgExtensionMessagesFiles) for backward compatibility purposes.
  6. The new format will be mandatory for all Wikimedia deployed code.
  7. Conversion scripts should be made available, and be performed for all Wikimedia-deployed extensions, expected by the time of the branching of MediaWiki 1.24.

The proposal is as follows

<?php
$messages = array();
array_map( function( $dir ) use ( &$messages ) {
	$files = glob( __DIR__ . "/$dir/*.json" );
	foreach ( $files as $file ) {
		$langcode = substr( basename( $file ), 0, -5 );
		$data = (array)json_decode( file_get_contents( $file ) );
		unset( $data['@metadata'] );
		$messages[$langcode] = array_merge( (array)$messages[$langcode], $data );
	}
}, array(
	'modules/oojs-ui/i18n',
	'modules/ve/i18n',
	'modules/ve-mw/i18n',
	'modules/ve-wmf/i18n'
) );

An extension with multiple groups of messages might choose to split its files up as follows:

The extension would load its values using $wgMessagesDirs['WikimediaMessages'] = __DIR__ . '/i18n';. This is short for $wgMessagesDirs['WikimediaMessages'] = array( '' => __DIR__ . '/i18n' );, and would load all message files in the above example automatically, including the namespacing.

A more complex use case is for extensions that use libraries, where moving the internationalisation files into the root of the extension would split the import and make things more complicated. A (slightly artificial) example might be:

For this example, the messages files would be loaded using:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4