r106491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106490‎ | r106491 | r106492 >
Date:01:08, 17 December 2011
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
beginning to build CountryNames
Modified paths:
  • /trunk/extensions/cldr/CountryNames.body.php (modified) (history)
  • /trunk/extensions/cldr/LanguageNames.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/cldr/CountryNames.body.php
@@ -3,10 +3,68 @@
44 /**
55 * A class for querying translated country names from CLDR data.
66 *
7 - * @author Niklas Laxström
8 - * @copyright Copyright © 2007-2008, Niklas Laxström
 7+ * @author Niklas Laxström, Ryan Kaldari
 8+ * @copyright Copyright © 2007-2011
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
1111 class CountryNames {
12 - // TODO: build this class
 12+
 13+ private static $cache = array();
 14+
 15+ const LIST_CLDR = 0; // Return all countries listed in CLDR
 16+ const LIST_FUNDRAISING = 1; // Return only countries that are not embargoed
 17+
 18+ /**
 19+ * Get localized country names for a particular language, using fallback languages for missing
 20+ * items.
 21+ *
 22+ * @param string $code The language to return the list in
 23+ * @param int $fbMethod The fallback method
 24+ * @param int $list Which type of list to return
 25+ * @return an associative array of country codes and localized country names
 26+ */
 27+ public static function getNames( $code, $list = self::LIST_CLDR ) {
 28+ // Load country names localized for the requested language
 29+ $names = self::loadLanguage( $code );
 30+
 31+ // Load missing country names from fallback languages
 32+ $fallbacks = Language::getFallbacksFor( $code );
 33+ foreach ( $fallbacks as $fallback ) {
 34+ // Overwrite the things in fallback with what we have already
 35+ $names = array_merge( self::loadLanguage( $fallback ), $names );
 36+ }
 37+
 38+ if ( $list == self::LIST_FUNDRAISING ) {
 39+ // Remove embargoed countries
 40+ unset( $names['CU'] ); // Cuba
 41+ unset( $names['IR'] ); // Iran
 42+ unset( $names['SY'] ); // Syria
 43+ }
 44+ }
 45+
 46+ /**
 47+ * Load country names localized for a particular language.
 48+ *
 49+ * @param string $code The language to return the list in
 50+ * @return an associative array of country codes and localized country names
 51+ */
 52+ private static function loadLanguage( $code ) {
 53+ // TODO: Build this.
 54+ }
 55+
 56+ /**
 57+ * @param string $code
 58+ * @return string
 59+ */
 60+ public static function getFileName( $code ) {
 61+ return Language::getFileName( "CldrNames", $code, '.php' );
 62+ }
 63+
 64+ /**
 65+ * @param string $code
 66+ * @return string
 67+ */
 68+ public static function getOverrideFileName( $code ) {
 69+ return Language::getFileName( "LocalNames", $code, '.php' );
 70+ }
1371 }
Index: trunk/extensions/cldr/LanguageNames.body.php
@@ -36,7 +36,7 @@
3737 $fallbacks = Language::getFallbacksFor( $code );
3838 $fb = $xx;
3939 foreach ( $fallbacks as $fallback ) {
40 - /* Over write the things in fallback with what we have already */
 40+ /* Overwrite the things in fallback with what we have already */
4141 $fb = array_merge( self::loadLanguage( $fallback ), $fb );
4242 }
4343

Follow-up revisions

RevisionCommit summaryAuthorDate
r106551follow-up to r106491 and r106496 - fixing for 1.19, moving embargo filter out...kaldari02:59, 18 December 2011

Comments

#Comment by MZMcBride (talk | contribs)   01:16, 17 December 2011

<Dmcdevit> North Korea is okay?

#Comment by Siebrand (talk | contribs)   11:02, 17 December 2011

I appreciate the need to exclude some codes for legal reasons in the fundraiser, but could we maybe find a more generic global me for it than self::LIST_FUNDRAISING?

#Comment by Kaldari (talk | contribs)   03:01, 18 December 2011

Fixed in r106551.

#Comment by Nikerabbit (talk | contribs)   20:59, 17 December 2011

This seems indeed a bit weird place to implement that kind of filtering. I would keep this just as data provided and do filtering on the callers.

You can use multiple @author tags.

Status & tagging log