Page MenuHomePhabricator

Structured localization framework for gadgets
Open, Needs TriagePublic

Description

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:

Related Objects

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:

https://commons.wikimedia.org/wiki/MediaWiki:Gadget-ProveIt.js
// Get the latest English messages
$.get( '//gerrit.wikimedia.org/r/plugins/gitiles/wikipedia/gadgets/ProveIt/+/master/i18n/en.json?format=text', 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( '//gerrit.wikimedia.org/r/plugins/gitiles/wikipedia/gadgets/ProveIt/+/master/i18n/' + 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
		ProveIt.buildList();
	} );
} );

Localization files are updating from translatewiki.net.

I was surprised to learn this wasn't implemented. Agree this would be beneficial - would reduce a lot of cargo-cult programming copy/pasting across projects if localizing a gadget was simply a case of loading a gadget from a foreign wiki alongside a localization module local to that wiki.

Change 993205 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/Gadgets@master] Allow gadgets to support messages

https://gerrit.wikimedia.org/r/993205

I am confused what this task is about. Gadgets do support messages. It is possible to commit messages to Wikimedia-messages and use them from gadgets at any wiki.

I am confused what this task is about. Gadgets do support messages. It is possible to commit messages to Wikimedia-messages and use them from gadgets at any wiki.

Here are talking more about convenient translation and convenient storage of messages. Now there is the only fast way to receive translated messages - through gerrit.

Now there is the only fast way to receive translated messages - through gerrit.

To receive? No, through Resource loader I believe. Gerrit is only to publish the message for translation. The translations themselves are done on TWN

Change 993205 abandoned by Jdlrobson:

[mediawiki/extensions/Gadgets@master] Allow gadgets to support messages

Reason:

Obviously needs some more thought. :)

https://gerrit.wikimedia.org/r/993205