From b9f7fe0bcf60d3fea5fc305ddbbaab7c339e75b1 Mon Sep 17 00:00:00 2001 From: Liangent Date: Tue, 29 May 2012 17:56:21 +0800 Subject: [PATCH] Display converted namespace names in Html::namespaceSelector(). By the way, the code to get converted titles and namespaces has been cleaned up. Change-Id: Ifcbd56c989d83b9d32dfa99e0b2f06d01e17a2bd --- includes/Html.php | 4 +++- languages/Language.php | 11 +++++++++ languages/LanguageConverter.php | 41 +++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index f4a3b55571..8cb99f55cd 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -796,10 +796,12 @@ class Html { if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) { continue; } - if ( $nsId === 0 ) { + if ( $nsId === NS_MAIN ) { // For other namespaces use use the namespace prefix as label, but for // main we don't use "" but the user message descripting it (e.g. "(Main)" or "(Article)") $nsName = wfMessage( 'blanknamespace' )->text(); + } elseif ( is_int( $nsId ) ) { + $nsName = $wgContLang->convertNamespace( $nsId ); } $optionsHtml[] = Html::element( 'option', array( diff --git a/languages/Language.php b/languages/Language.php index d3841c91bb..c4807a61d3 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -54,6 +54,7 @@ class FakeConverter { function convert( $t ) { return $t; } function convertTo( $text, $variant ) { return $text; } function convertTitle( $t ) { return $t->getPrefixedText(); } + function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); } function getVariants() { return array( $this->mLang->getCode() ); } function getPreferredVariant() { return $this->mLang->getCode(); } function getDefaultVariant() { return $this->mLang->getCode(); } @@ -3546,6 +3547,16 @@ class Language { return $this->mConverter->convertTitle( $title ); } + /** + * Convert a namespace index to a string in the preferred variant + * + * @param $ns int + * @return string + */ + public function convertNamespace( $ns ) { + return $this->mConverter->convertNamespace( $ns ); + } + /** * Check if this is a language with variants * diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 82e6359f1d..bf5c217acc 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -550,24 +550,41 @@ class LanguageConverter { public function convertTitle( $title ) { $variant = $this->getPreferredVariant(); $index = $title->getNamespace(); - if ( $index === NS_MAIN ) { + if ( $index !== NS_MAIN ) { + $text = $this->convertNamespace( $index ) . ':'; + } else { $text = ''; + } + $text .= $this->translate( $title->getText(), $variant ); + return $text; + } + + /** + * Get the namespace display name in the preferred variant. + * + * @param $index int namespace id + * @return String: namespace name for display + */ + public function convertNamespace( $index ) { + $variant = $this->getPreferredVariant(); + if ( $index === NS_MAIN ) { + return ''; } else { - // first let's check if a message has given us a converted name + // First check if a message gives a converted name in the target variant. + $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant ); + if ( $nsConvMsg->exists() ) { + return $nsConvMsg->plain(); + } + // Then check if a message gives a converted name in content language + // which needs extra translation to the target variant. $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage(); if ( $nsConvMsg->exists() ) { - $text = $nsConvMsg->plain(); - } else { - // the message does not exist, try retrieve it from the current - // variant's namespace names. - $langObj = $this->mLangObj->factory( $variant ); - $text = $langObj->getFormattedNsText( $index ); + return $this->translate( $nsConvMsg->plain(), $variant ); } - $text .= ':'; + // No message exists, retrieve it from the target variant's namespace names. + $langObj = $this->mLangObj->factory( $variant ); + return $langObj->getFormattedNsText( $index ); } - $text .= $title->getText(); - $text = $this->translate( $text, $variant ); - return $text; } /** -- 2.20.1