From 35383a74e32068f624e44ee60f22f94b7db56e25 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Wed, 7 Jan 2009 19:19:25 +0000 Subject: [PATCH] * Extend language::getLanguageName to return localized language names if available * 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 | 4 ++++ includes/SkinTemplate.php | 9 +++++++-- languages/Language.php | 20 ++++++++++++++++++-- skins/Modern.php | 10 ++++++++-- skins/MonoBook.php | 10 ++++++++-- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 04b1e2ac8e..a6acdb6d7d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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) diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index f44c655ba9..f61104f453 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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 ) ); } } diff --git a/languages/Language.php b/languages/Language.php index 6502aa0d4f..eaec2b671e 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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 ) { diff --git a/skins/Modern.php b/skins/Modern.php index c16ae47668..9a55ab45c0 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -332,9 +332,15 @@ class ModernTemplate extends QuickTemplate {
msg('otherlanguages') ?>
diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 62d98baa7c..f4724e4308 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -334,9 +334,15 @@ class MonoBookTemplate extends QuickTemplate {
msg('otherlanguages') ?>
-- 2.20.1