Index: trunk/extensions/cldr/CountryNames.body.php |
— | — | @@ -3,10 +3,68 @@ |
4 | 4 | /** |
5 | 5 | * A class for querying translated country names from CLDR data. |
6 | 6 | * |
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 |
9 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 10 | */ |
11 | 11 | 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 | + } |
13 | 71 | } |
Index: trunk/extensions/cldr/LanguageNames.body.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | $fallbacks = Language::getFallbacksFor( $code ); |
38 | 38 | $fb = $xx; |
39 | 39 | 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 */ |
41 | 41 | $fb = array_merge( self::loadLanguage( $fallback ), $fb ); |
42 | 42 | } |
43 | 43 | |