Index: trunk/extensions/cldr/CountryNames.body.php |
— | — | @@ -3,7 +3,8 @@ |
4 | 4 | /** |
5 | 5 | * A class for querying translated country names from CLDR data. |
6 | 6 | * |
7 | | - * @author Niklas Laxström, Ryan Kaldari |
| 7 | + * @author Niklas Laxström |
| 8 | + * @author Ryan Kaldari |
8 | 9 | * @copyright Copyright © 2007-2011 |
9 | 10 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 11 | */ |
— | — | @@ -11,36 +12,35 @@ |
12 | 13 | |
13 | 14 | private static $cache = array(); |
14 | 15 | |
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 | 16 | /** |
19 | 17 | * Get localized country names for a particular language, using fallback languages for missing |
20 | 18 | * items. |
21 | 19 | * |
22 | 20 | * @param string $code The language to return the list in |
23 | 21 | * @param int $fbMethod The fallback method |
24 | | - * @param int $list Which type of list to return |
25 | 22 | * @return an associative array of country codes and localized country names |
26 | 23 | */ |
27 | | - public static function getNames( $code, $list = self::LIST_CLDR ) { |
| 24 | + public static function getNames( $code ) { |
28 | 25 | // Load country names localized for the requested language |
29 | 26 | $names = self::loadLanguage( $code ); |
30 | 27 | |
31 | 28 | // Load missing country names from fallback languages |
32 | | - $fallback = $code; |
33 | | - while ( $fallback = Language::getFallbackFor( $fallback ) ) { |
34 | | - // Overwrite the things in fallback with what we have already |
35 | | - $names = array_merge( self::loadLanguage( $fallback ), $names ); |
| 29 | + if ( is_callable( array( 'Language', 'getFallbacksFor' ) ) ) { |
| 30 | + // MediaWiki 1.19 |
| 31 | + $fallbacks = Language::getFallbacksFor( $code ); |
| 32 | + foreach ( $fallbacks as $fallback ) { |
| 33 | + // Overwrite the things in fallback with what we have already |
| 34 | + $names = array_merge( self::loadLanguage( $fallback ), $names ); |
| 35 | + } |
| 36 | + } else { |
| 37 | + // MediaWiki 1.18 or earlier |
| 38 | + $fallback = $code; |
| 39 | + while ( $fallback = Language::getFallbackFor( $fallback ) ) { |
| 40 | + // Overwrite the things in fallback with what we have already |
| 41 | + $names = array_merge( self::loadLanguage( $fallback ), $names ); |
| 42 | + } |
36 | 43 | } |
37 | 44 | |
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 | 45 | return $names; |
46 | 46 | } |
47 | 47 | |
Index: trunk/extensions/cldr/LanguageNames.body.php |
— | — | @@ -33,11 +33,23 @@ |
34 | 34 | if ( $fbMethod === self::FALLBACK_NATIVE ) { |
35 | 35 | $names = array_merge( $native, $xx ); |
36 | 36 | } elseif ( $fbMethod === self::FALLBACK_NORMAL ) { |
37 | | - $fallback = $code; |
| 37 | + |
| 38 | + // Load missing language names from fallback languages |
38 | 39 | $fb = $xx; |
39 | | - while ( $fallback = Language::getFallbackFor( $fallback ) ) { |
40 | | - /* Overwrite the things in fallback with what we have already */ |
41 | | - $fb = array_merge( self::loadLanguage( $fallback ), $fb ); |
| 40 | + if ( is_callable( array( 'Language', 'getFallbacksFor' ) ) ) { |
| 41 | + // MediaWiki 1.19 |
| 42 | + $fallbacks = Language::getFallbacksFor( $code ); |
| 43 | + foreach ( $fallbacks as $fallback ) { |
| 44 | + // Overwrite the things in fallback with what we have already |
| 45 | + $fb = array_merge( self::loadLanguage( $fallback ), $fb ); |
| 46 | + } |
| 47 | + } else { |
| 48 | + // MediaWiki 1.18 or earlier |
| 49 | + $fallback = $code; |
| 50 | + while ( $fallback = Language::getFallbackFor( $fallback ) ) { |
| 51 | + // Overwrite the things in fallback with what we have already |
| 52 | + $fb = array_merge( self::loadLanguage( $fallback ), $fb ); |
| 53 | + } |
42 | 54 | } |
43 | 55 | |
44 | 56 | /* Add native names for codes that are not in cldr */ |