Page MenuHomePhabricator

Add a global array for custom messages
Closed, DeclinedPublic

Assigned To
None
Authored By
bzimport
Jun 20 2006, 12:29 PM
Referenced Files
F3059: patch
Nov 21 2014, 9:20 PM
F3058: newer_example
Nov 21 2014, 9:20 PM
F3056: example_old
Nov 21 2014, 9:20 PM
F3057: example_new
Nov 21 2014, 9:20 PM

Description

Author: rotemliss

Description:
Currently, all the extensions use $wgMessageCache->addMessages to add system
messages, and usually don't translate them into other languages.

Actually, translating the extensions into other languages is something hard
using the current tools. We can check $wgLanguageCode to get the current
language, use "if" structure and add the localized messages, but some messages
are interface messages and should be retrieved from the user-chosen language
($wgLanguageCode), while others are content messages and should retrieved from
the site content language ($wgContLanguageCode). We can build two "if"
statements, but the code is getting longer and more complicated. Finally, there
is a special type of messages – log entry messages. These messages should be
used as content messages when executing the action and getting the log entry
into the recent changes comment, and as interface messages in Special:Log. This
usage is completely not possible to implement with extension system messages,
and is not possible to implement using $wgMessageCache->addMessages.

Even without taking notice to the log entry messages, something like that should
be used to add a new user group:

Allow only privilleged users to import pages

$wgGroupPermissions["sysop"]["import"] = false;
$wgGroupPermissions["import"]["import"] = true;

Add the interface messages

if ($wgLanguageCode == 'en') {
$wgMessagesCache->addMessages( array(

		"group-import" => "Importers",
		"group-import-member" => "Importer",

) );
} elseif ($wgLanguageCode == 'he') {
$wgMessagesCache->addMessages( array(

		"group-import" => "מייבאים",
		"group-import-member" => "מייבא",

) );
}

Add the content messages

if ($wgContLanguageCode == 'en') {
$wgMessagesCache->addMessages( array(

		"grouppage-import" => "{{ns:help}}:Import",

) );
} elseif ($wgContLanguageCode == 'he') {
$wgMessagesCache->addMessages( array(

		"grouppage-import" => "{{ns:help}}:ייבוא",

) );
}

This code is complicated, not organized and not understandable. It breaks the
array $wgForceUIMsgAsContentMsg or a change in its use, bypasses wfMsg vs.
wfMsgForContent, and as I've already said, we cannot bypass the problem in such
way for log entries.

Therefore, I've suggested here:
http://mail.wikipedia.org/pipermail/mediawiki-i18n/2006-May/000063.html new
hooks, which pass the messages as an argument, and messages can be added to
them. I've published the code and checks here:
http://mail.wikipedia.org/pipermail/mediawiki-i18n/2006-June/000076.html and you
can see that the following code is much cleaner:

Allow only privilleged users to import pages

$wgGroupPermissions["sysop"]["import"] = false;
$wgGroupPermissions["import"]["import"] = true;

Translation hooks

$wgHooks['AddMessagesEn'][] = 'wfImportMessagesEn';
$wgHooks['AddMessagesHe'][] = 'wfImportMessagesHe';

English messages

function wfImportMessagesEn( &$messages ) {
$messages += array(

		"group-import" => "Importers",
		"group-import-member" => "Importer",
		"grouppage-import" => "{{ns:help}}:Import",

);
return true;
}

Hebrew messages

function wfImportMessagesHe( &$messages ) {
$messages += array(

		"group-import" => "מייבאים",
		"group-import-member" => "מייבא",
		"grouppage-import" => "{{ns:help}}:ייבוא",

);
return true;
}

I'm posting the most updated patch here, and it would be nice if you make some
comments about it, or suggest a better way.

Thanks.


Version: 1.7.x
Severity: enhancement
URL: http://mail.wikipedia.org/pipermail/mediawiki-i18n/2006-May/000063.html

Details

Reference
bz6382

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 9:20 PM
bzimport set Reference to bz6382.
bzimport added a subscriber: Unknown Object (MLST).

rotemliss wrote:

Patch (trunk)

The hooks I've described above.

attachment patch ignored as obsolete

rotemliss wrote:

Example for a code using the current "addMessages"

Attached:

rotemliss wrote:

Example for a code using the hooks

Attached:

rotemliss wrote:

Thinking again, a global messages array will be even better: the code for adding
the messages is much shorter than in any other way, and no hooks should be used.
I'm going to try implementing this.

rotemliss wrote:

Example for a code using the global array

The code is now even shorter.

Attached:

rotemliss wrote:

Patch (trunk)

This is the code suggestion. The example code is working on it. What do you
think about it? Do you have other suggestions?

Attached:

rotemliss wrote:

Added additional parameter to MessageCache::addMessages instead.