better support for on-wiki i18n

This commit is contained in:
Daniel Kinzler 2008-08-17 15:42:26 +00:00
parent 22d6131db0
commit e6010c67cc
2 changed files with 37 additions and 3 deletions

View file

@ -32,6 +32,7 @@ $wgHooks['RenderPreferencesForm'][] = 'wfGadgetsRenderPreferencesForm';
$wgHooks['ResetPreferences'][] = 'wfGadgetsResetPreferences';
$wgHooks['BeforePageDisplay'][] = 'wfGadgetsBeforePageDisplay';
$wgHooks['ArticleSaveComplete'][] = 'wfGadgetsArticleSaveComplete';
$wgHooks['LoadAllMessages'][] = 'wfGadgetsInjectMessages';
$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['Gadgets'] = $dir . 'Gadgets.i18n.php';
@ -231,3 +232,31 @@ function wfApplyGadgetCode( $code, &$out, &$done ) {
}
}
}
/**
* inject descriptions into system messages, so they show on Special:Allmessages
*/
function wfGadgetsInjectMessages() {
global $wgLang, $wgMessageCache;
$gadgets = wfLoadGadgetsStructured();
if ( !$gadgets ) return true;
$messages = array();
foreach ( $gadgets as $section => $entries ) {
if ( $section !== false && $section !== '' ) {
$tname = "gadget-section-$section";
$messages[$tname] = $section;
}
foreach ( $entries as $gname => $code ) {
$tname = "gadget-$gname";
$messages[$tname] = $gname;
}
}
$wgMessageCache->addMessages( $messages );
return true;
}

View file

@ -30,7 +30,7 @@ class SpecialGadgets extends SpecialPage {
* @param $par Parameters passed to the page
*/
function execute( $par ) {
global $wgOut, $wgUser;
global $wgOut, $wgUser, $wgLang, $wgContLang;
wfLoadExtensionMessages( 'Gadgets' );
$skin = $wgUser->getSkin();
@ -42,13 +42,18 @@ class SpecialGadgets extends SpecialPage {
$gadgets = wfLoadGadgetsStructured();
if ( !$gadgets ) return;
$lang = "";
if ( $wgLang->getCode() != $wgContLang->getCode() ) {
$lang = "/" . $wgLang->getCode();
}
$listOpen = false;
$msgOpt = array( 'parseinline', 'parsemag' );
foreach ( $gadgets as $section => $entries ) {
if ( $section !== false && $section !== '' ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section" );
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
$lnk = $t ? $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' ) : htmlspecialchars($section);
$ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
@ -60,7 +65,7 @@ class SpecialGadgets extends SpecialPage {
}
foreach ( $entries as $gname => $code ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname" );
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
if ( !$t ) continue;
$lnk = $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' );