r79359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79358‎ | r79359 | r79360 >
Date:18:18, 31 December 2010
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
New method for making it easier for developers to get localised language names.
For now the core itself doesn't provide those, but extension can use the hook
to provide them. Callers should not except full coverage in every language.
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -992,6 +992,10 @@
993993 $specialPageAliases: associative array of magic words synonyms
994994 $lang: laguage code (string)
995995
 996+'LanguageGetTranslatedLanguageNames': Provide translated language names.
 997+&$names: array of language code => language name
 998+$code language of the preferred translations
 999+
9961000 'LinkBegin': Used when generating internal and interwiki links in
9971001 Linker::link(), before processing starts. Return false to skip default proces-
9981002 sing and return $ret. See documentation for Linker::link() for details on the
Index: trunk/phase3/languages/Language.php
@@ -488,6 +488,25 @@
489489 }
490490
491491 /**
 492+ * Get translated language names. This is done on best effort and
 493+ * by default this is exactly the same as Language::getLanguageNames.
 494+ * The CLDR extension provides translated names.
 495+ * @param $code String Language code.
 496+ * @return Array language code => language name
 497+ * @since 1.18.0
 498+ */
 499+ public static function getTranslatedLanguageNames( $code ) {
 500+ $names = array();
 501+ wfRunHooks( 'LanguageGetTranslatedLanguageNames', array( &$names, $code ) );
 502+
 503+ foreach ( self::getLanguageNames() as $code => $name ) {
 504+ if ( !isset( $names[$code] ) ) $names[$code] = $name;
 505+ }
 506+
 507+ return $names;
 508+ }
 509+
 510+ /**
492511 * Get a message from the MediaWiki namespace.
493512 *
494513 * @param $msg String: message name

Comments

#Comment by Aaron Schulz (talk | contribs)   21:24, 14 June 2011

Nifty.

Status & tagging log