Page MenuHomePhabricator

Structured localization framework for gadgets
Open, Needs TriagePublic


Gadgets that are useful in more than one language need a convenient and uniform localization framework for translating their messages.

This is needed for gadgets that are used across wikis, and even for gadgets that are used in multilingual wikis such as Commons or Wikidata.

At the moment there is no such framework, and this causes several difficulties:

  • Gadgets usually rely on editing raw JavaScript or JSON, which is inconvenient for people who are generally uncomfortable with code and especially for people who write in right-to-left alphabets and other scripts that don't work well in plain text.
  • Gadget source code is stored on wiki pages, which are usually protected, and every localization update requires the involvement of a sysadmin or an interface editor.
  • The API for loading, parsing, and displaying the messages is inconsistent and different gadgets use different functions for this.

It would be much nicer if gadgets could be translated the same way as extensions are: using a dedicated translation interface so that translators wouldn't have to deal with any code (probably with the Translate extension), letting everyone update translations in true wiki style ("anyone can edit"), and using a consistent API for message parsing, including all the MediaWiki features such as PLURAL, GRAMMAR, etc.

This will possibly require some adaptation in the Gadgets extension and the Translate extension, and some updates in the gadgets themselves, but it will make life easier for everyone.

This task is specifically for gadgets. Templates and modules have some similar requirements, but they are handled in other tasks. See also:

Event Timeline

Amire80 renamed this task from Structured localization framework for Gadgets to Structured localization framework for gadgets.Nov 15 2019, 4:43 PM

There is another option how gadgets can be localized. For example, ProveIt-Gadget and Convenient-Discussions use localization strings from gerrit:
// Get the latest English messages
$.get( '//', function ( data ) {

	var englishMessages = JSON.parse( ProveIt.decodeBase64( data ) );
	delete englishMessages[ '@metadata' ];

	// Get the latest translations to the preferred user language
	var userLanguage = mw.config.get( 'wgUserLanguage' );
	$.get( '//' + userLanguage + '.json?format=text' ).always( function ( data, status ) {

		$( '#proveit-logo-text' ).text( 'ProveIt' ); // Finish loading

		var translatedMessages = {};
		if ( status === 'success' ) {
			translatedMessages = JSON.parse( ProveIt.decodeBase64( data ) );
			delete translatedMessages[ '@metadata' ];

		// Merge and set the messages
		var messages = $.extend( {}, englishMessages, translatedMessages );
		mw.messages.set( messages );

		// Finally, build the list
	} );
} );

Localization files are updating from