Last modified: 2011-03-13 18:06:14 UTC
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.
Created attachment 1991 [details] Patch (trunk) The hooks I've described above.
Created attachment 1992 [details] Example for a code using the current "addMessages"
Created attachment 1993 [details] Example for a code using the hooks
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.
Created attachment 2010 [details] Example for a code using the global array The code is now even shorter.
Created attachment 2011 [details] 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?
Added additional parameter to MessageCache::addMessages instead.