From e6010c67cc383dbbe084a577a865952cda364f62 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Sun, 17 Aug 2008 15:42:26 +0000 Subject: [PATCH] better support for on-wiki i18n --- Gadgets.php | 29 +++++++++++++++++++++++++++++ SpecialGadgets.php | 11 ++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Gadgets.php b/Gadgets.php index 9c542c7a..f2081494 100644 --- a/Gadgets.php +++ b/Gadgets.php @@ -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; +} + diff --git a/SpecialGadgets.php b/SpecialGadgets.php index 2993b1ad..8e2ae28c 100644 --- a/SpecialGadgets.php +++ b/SpecialGadgets.php @@ -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' );