* Extend language::getLanguageName to return localized language names if available
authorRaimond Spekking <raymond@users.mediawiki.org>
Wed, 7 Jan 2009 19:19:25 +0000 (19:19 +0000)
committerRaimond Spekking <raymond@users.mediawiki.org>
Wed, 7 Jan 2009 19:19:25 +0000 (19:19 +0000)
* Therefore added a hook to catch them from an extension (successfully tested with the cldr extension (see next commit))
* Add a title tag to the interlanguage box entries. Only added when the title differ from the shwon text.
No change of behaviour until an extension is enabled.

docs/hooks.txt
includes/SkinTemplate.php
languages/Language.php
skins/Modern.php
skins/MonoBook.php

index 04b1e2a..a6acdb6 100644 (file)
@@ -783,6 +783,10 @@ $password: The password entered by the user
 &$result: Set this and return false to override the internal checks
 $user: User the password is being validated for
 
+'LanguageGetLocalizedLanguageNames': Use to get localized language names
+&$languageNames: localized language names (array)
+$lang: laguage code (string)
+
 'LanguageGetMagic': Use this to define synonyms of magic words depending of the language
 $magicExtensions: associative array of magic words synonyms
 $lang: laguage code (string)
index f44c655..f61104f 100644 (file)
@@ -416,8 +416,13 @@ class SkinTemplate extends Skin {
                                if ( $nt ) {
                                        $language_urls[] = array(
                                                'href' => $nt->getFullURL(),
-                                               'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
-                                               'class' => $class
+                                               'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != ''
+                                                       ? $wgContLang->getLanguageName( $nt->getInterwiki() )
+                                                       : $l ),
+                                               'class' => $class,
+                                               'title' => ( $wgLang->getLanguageNameLocalized( $nt->getInterwiki() ) != ''
+                                                       ? $wgLang->getLanguageNameLocalized( $nt->getInterwiki() )
+                                                       : $l )
                                        );
                                }
                        }
index 6502aa0..eaec2b6 100644 (file)
@@ -419,12 +419,28 @@ class Language {
                return wfMsgExt( $msg, array( 'parsemag', 'language' => $this ) );
        }
 
-       function getLanguageName( $code ) {
+       /**
+        * Get a language name
+        *
+        * @param $code String language code
+        * @return $localized boolean gets the localized language name
+        */
+       function getLanguageName( $code, $localized = false ) {
                $names = self::getLanguageNames();
                if ( !array_key_exists( $code, $names ) ) {
                        return '';
                }
-               return $names[$code];
+               if( $localized ) {
+                       $languageNames = array();
+                       wfRunHooks( 'LanguageGetLocalizedLanguageNames', array( &$languageNames, $this->getCode() ) );
+                       return isset( $languageNames[$code] ) ? $languageNames[$code] : $names[$code];
+               } else {
+                       return $names[$code];
+               }
+       }
+
+       function getLanguageNameLocalized( $code ) {
+               return self::getLanguageName( $code, true );
        }
 
        function getMonthName( $key ) {
index c16ae47..9a55ab4 100644 (file)
@@ -332,9 +332,15 @@ class ModernTemplate extends QuickTemplate {
                <h5><?php $this->msg('otherlanguages') ?></h5>
                <div class="pBody">
                        <ul>
-<?php          foreach($this->data['language_urls'] as $langlink) { ?>
+<?php          foreach($this->data['language_urls'] as $langlink) {
+                       // Add title tag only if differ from shown text
+                       $titleTag = $langlink['title'] == $langlink['text'] 
+                               ? ''
+                               : 'title="' . htmlspecialchars( $langlink['title'] ) . '"';
+                       ?>
                                <li class="<?php echo htmlspecialchars($langlink['class'])?>"><?php
-                               ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"><?php echo $langlink['text'] ?></a></li>
+                               ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"
+                               <? echo $titleTag ?> > <?php echo $langlink['text'] ?></a></li>
 <?php          } ?>
                        </ul>
                </div><!-- pBody -->
index 62d98ba..f4724e4 100644 (file)
@@ -334,9 +334,15 @@ class MonoBookTemplate extends QuickTemplate {
                <h5><?php $this->msg('otherlanguages') ?></h5>
                <div class="pBody">
                        <ul>
-<?php          foreach($this->data['language_urls'] as $langlink) { ?>
+<?php          foreach($this->data['language_urls'] as $langlink) {
+                       // Add title tag only if differ from shown text
+                       $titleTag = $langlink['title'] == $langlink['text'] 
+                               ? ''
+                               : 'title="' . htmlspecialchars( $langlink['title'] ) . '"';
+                       ?>
                                <li class="<?php echo htmlspecialchars($langlink['class'])?>"><?php
-                               ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"><?php echo $langlink['text'] ?></a></li>
+                               ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"
+                               <? echo $titleTag ?> > <?php echo $langlink['text'] ?></a></li>
 <?php          } ?>
                        </ul>
                </div>