r106912 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106911‎ | r106912 | r106913 >
Date:01:14, 21 December 2011
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
adding CLDR support to XML::languageSelector()
Modified paths:
  • /branches/fundraising/vendors/mediawiki/current/includes/Xml.php (modified) (history)

Diff [purge]

Index: branches/fundraising/vendors/mediawiki/current/includes/Xml.php
@@ -208,21 +208,39 @@
209209 }
210210
211211 /**
212 - *
213 - * @param $selected The language code of the selected language
214 - * @param $customisedOnly If true only languages which have some content are listed
215 - * @return array of label and select
 212+ * Construct a language selector appropriate for use in a form or preferences
 213+ *
 214+ * @param string $selected The language code of the selected language
 215+ * @param boolean $customisedOnly If true only languages which have some content are listed
 216+ * @param string $language The ISO code of the language to display the select list in (optional)
 217+ * @return array containing 2 items: label HTML and select list HTML
216218 */
217 - public static function languageSelector( $selected, $customisedOnly = true ) {
 219+ public static function languageSelector( $selected, $customisedOnly = true, $language = NULL ) {
218220 global $wgLanguageCode;
219 - /**
220 - * Make sure the site language is in the list; a custom language code
221 - * might not have a defined name...
222 - */
223 - $languages = Language::getLanguageNames( $customisedOnly );
 221+
 222+ // If a specific language was requested and CLDR is installed, use it
 223+ if ( $language && is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
 224+ if ( $customisedOnly ) {
 225+ $listType = LanguageNames::LIST_MW_SUPPORTED; // Only pull names that have localisation in MediaWiki
 226+ } else {
 227+ $listType = LanguageNames::LIST_MW; // Pull all languages that are in Names.php
 228+ }
 229+ // Retrieve the list of languages in the requested language (via CLDR)
 230+ $languages = LanguageNames::getNames(
 231+ $language, // Code of the requested language
 232+ LanguageNames::FALLBACK_NORMAL, // Use fallback chain
 233+ $listType
 234+ );
 235+ } else {
 236+ $languages = Language::getLanguageNames( $customisedOnly );
 237+ }
 238+
 239+ // Make sure the site language is in the list; a custom language code might not have a
 240+ // defined name...
224241 if( !array_key_exists( $wgLanguageCode, $languages ) ) {
225242 $languages[$wgLanguageCode] = $wgLanguageCode;
226243 }
 244+
227245 ksort( $languages );
228246
229247 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r106914now with CLDR! This rev depends on r106912kaldari01:15, 21 December 2011
r107002follow-up to r106912, making change to correct branch this timekaldari22:54, 21 December 2011
r108065follow-up to r106912 - NULL to nullkaldari19:01, 4 January 2012

Comments

#Comment by NeilK (talk | contribs)   02:34, 21 December 2011

looks good to me, but perhaps someone with more CLDR experience should have another look.

#Comment by Nikerabbit (talk | contribs)   07:45, 21 December 2011

Code style: null in lowercase.

I was going to suggest using Language::getTranslatedLanguageNames but you would have to do the filtering of unwanted language codes anyway.

#Comment by Awjrichards (talk | contribs)   22:51, 21 December 2011

This should also be done in trunk rather than in the fundraising MW branch (which is a slice of 1.17wmf1)

Status & tagging log