* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBDictionary' , 'WBString'); /** * Dictionary: Country * * Manage two letter country codes * * @version 0.1.1 * @package WB * @subpackage */ class WBDictionary_Country extends WBDictionary { /** * list of codes and names * @var array */ protected static $list = array(); /** * 2nd constructor * * load county codes and translate names */ public function init() { if (!empty(self::$list)) { return; } // initi list only once WBClass::create('patI18n'); self::$list = array( 'ad'=> patI18n::dgettext('wombat', 'Andorra'), 'ae'=> patI18n::dgettext('wombat', 'United Arab Emirates'), 'af'=> patI18n::dgettext('wombat', 'Afghanistan'), 'ag'=> patI18n::dgettext('wombat', 'Antigua and Barbuda'), 'ai'=> patI18n::dgettext('wombat', 'Anguilla'), 'al'=> patI18n::dgettext('wombat', 'Albania'), 'am'=> patI18n::dgettext('wombat', 'Armenia'), // 'an'=> patI18n::dgettext('wombat', 'Netherlands Antilles'), // transitionally reserved 'ao'=> patI18n::dgettext('wombat', 'Angola'), 'aq'=> patI18n::dgettext('wombat', 'Antarctica'), 'ar'=> patI18n::dgettext('wombat', 'Argentina'), 'as'=> patI18n::dgettext('wombat', 'American Samoa'), 'at'=> patI18n::dgettext('wombat', 'Austria'), 'au'=> patI18n::dgettext('wombat', 'Australia'), 'aw'=> patI18n::dgettext('wombat', 'Aruba'), 'ax'=> patI18n::dgettext('wombat', 'Aland Islands'), 'az'=> patI18n::dgettext('wombat', 'Azerbaijan'), 'ba'=> patI18n::dgettext('wombat', 'Bosnia-Herzegovina'), 'bb'=> patI18n::dgettext('wombat', 'Barbados'), 'bd'=> patI18n::dgettext('wombat', 'Bangladesh'), 'be'=> patI18n::dgettext('wombat', 'Belgium'), 'bf'=> patI18n::dgettext('wombat', 'Burkina Faso'), 'bg'=> patI18n::dgettext('wombat', 'Bulgaria'), 'bh'=> patI18n::dgettext('wombat', 'Bahrain'), 'bi'=> patI18n::dgettext('wombat', 'Burundi'), 'bj'=> patI18n::dgettext('wombat', 'Benin'), 'bl'=> patI18n::dgettext('wombat', 'Saint Barthélemy'), 'bm'=> patI18n::dgettext('wombat', 'Bermuda'), 'bn'=> patI18n::dgettext('wombat', 'Brunei Darussalam'), 'bo'=> patI18n::dgettext('wombat', 'Bolivia'), 'bq'=> patI18n::dgettext('wombat', 'Bonaire, Sint Eustatius and Saba'), 'br'=> patI18n::dgettext('wombat', 'Brazil'), 'bs'=> patI18n::dgettext('wombat', 'Bahamas'), 'bt'=> patI18n::dgettext('wombat', 'Bhutan'), 'bv'=> patI18n::dgettext('wombat', 'Bouvet Island'), 'bw'=> patI18n::dgettext('wombat', 'Botswana'), 'by'=> patI18n::dgettext('wombat', 'Belarus'), 'bz'=> patI18n::dgettext('wombat', 'Belize'), 'ca'=> patI18n::dgettext('wombat', 'Canada'), 'cc'=> patI18n::dgettext('wombat', 'Cocos (Keeling) Islands'), 'cd'=> patI18n::dgettext('wombat', 'Congo, the Democratic Republic of the'), 'cf'=> patI18n::dgettext('wombat', 'Central African Republic'), 'cg'=> patI18n::dgettext('wombat', 'Congo'), 'ch'=> patI18n::dgettext('wombat', 'Switzerland'), 'ci'=> patI18n::dgettext('wombat', 'Cote D-ivoire'), 'ck'=> patI18n::dgettext('wombat', 'Cook Islands'), 'cl'=> patI18n::dgettext('wombat', 'Chile'), 'cm'=> patI18n::dgettext('wombat', 'Cameroon'), 'cn'=> patI18n::dgettext('wombat', 'China'), 'co'=> patI18n::dgettext('wombat', 'Colombia'), 'cr'=> patI18n::dgettext('wombat', 'Costa Rica'), // 'cs'=> patI18n::dgettext('wombat', 'Serbia and Montenegro'), // transitionally reserved 'cu'=> patI18n::dgettext('wombat', 'Cuba'), 'cv'=> patI18n::dgettext('wombat', 'Cape Verde'), 'cx'=> patI18n::dgettext('wombat', 'Christmas Island'), 'cy'=> patI18n::dgettext('wombat', 'Cyprus'), 'cz'=> patI18n::dgettext('wombat', 'Czech Republic'), 'de'=> patI18n::dgettext('wombat', 'Germany'), 'dj'=> patI18n::dgettext('wombat', 'Djibouti'), 'dk'=> patI18n::dgettext('wombat', 'Denmark'), 'dm'=> patI18n::dgettext('wombat', 'Dominica'), 'do'=> patI18n::dgettext('wombat', 'Dominican Republic'), 'dz'=> patI18n::dgettext('wombat', 'Algeria'), 'ec'=> patI18n::dgettext('wombat', 'Ecuador'), 'ee'=> patI18n::dgettext('wombat', 'Estonia'), 'eg'=> patI18n::dgettext('wombat', 'Egypt'), 'eh'=> patI18n::dgettext('wombat', 'Western Sahara'), 'er'=> patI18n::dgettext('wombat', 'Eritrea'), 'es'=> patI18n::dgettext('wombat', 'Spain'), 'et'=> patI18n::dgettext('wombat', 'Ethiopia'), 'fi'=> patI18n::dgettext('wombat', 'Finland'), 'fj'=> patI18n::dgettext('wombat', 'Fiji'), 'fk'=> patI18n::dgettext('wombat', 'Falkland Islands'), 'fm'=> patI18n::dgettext('wombat', 'Micronesia'), 'fo'=> patI18n::dgettext('wombat', 'Faroe Islands'), 'fr'=> patI18n::dgettext('wombat', 'France'), 'ga'=> patI18n::dgettext('wombat', 'Gabon'), 'gb'=> patI18n::dgettext('wombat', 'United Kingdom'), 'gd'=> patI18n::dgettext('wombat', 'Grenada'), 'ge'=> patI18n::dgettext('wombat', 'Georgia'), 'gf'=> patI18n::dgettext('wombat', 'French Guiana'), 'gg'=> patI18n::dgettext('wombat', 'Guernsey'), 'gh'=> patI18n::dgettext('wombat', 'Ghana'), 'gi'=> patI18n::dgettext('wombat', 'Gibraltar'), 'gl'=> patI18n::dgettext('wombat', 'Greenland'), 'gm'=> patI18n::dgettext('wombat', 'Gambia'), 'gn'=> patI18n::dgettext('wombat', 'Guinea'), 'gp'=> patI18n::dgettext('wombat', 'Guadeloupe'), 'gq'=> patI18n::dgettext('wombat', 'Equatorial Guinea'), 'gr'=> patI18n::dgettext('wombat', 'Greece'), 'gs'=> patI18n::dgettext('wombat', 'South Georgia and the South Sandwich Islands'), 'gt'=> patI18n::dgettext('wombat', 'Guatemala'), 'gu'=> patI18n::dgettext('wombat', 'Guam'), 'gw'=> patI18n::dgettext('wombat', 'Guinea-Bissau'), 'gy'=> patI18n::dgettext('wombat', 'Guyana'), 'hk'=> patI18n::dgettext('wombat', 'Hong Kong'), 'hm'=> patI18n::dgettext('wombat', 'Heard Island And McDonald Islands'), 'hn'=> patI18n::dgettext('wombat', 'Honduras'), 'hr'=> patI18n::dgettext('wombat', 'Croatia'), 'ht'=> patI18n::dgettext('wombat', 'Haiti'), 'hu'=> patI18n::dgettext('wombat', 'Hungary'), 'id'=> patI18n::dgettext('wombat', 'Indonesia'), 'ie'=> patI18n::dgettext('wombat', 'Ireland'), 'il'=> patI18n::dgettext('wombat', 'Israel'), 'im'=> patI18n::dgettext('wombat', 'Isle of Man'), 'in'=> patI18n::dgettext('wombat', 'India'), 'io'=> patI18n::dgettext('wombat', 'British Indian Ocean Territories'), 'iq'=> patI18n::dgettext('wombat', 'Iraq'), 'ir'=> patI18n::dgettext('wombat', 'Iran, Islamic Republic of'), 'is'=> patI18n::dgettext('wombat', 'Iceland'), 'it'=> patI18n::dgettext('wombat', 'Italy'), 'je'=> patI18n::dgettext('wombat', 'Jersey'), 'jm'=> patI18n::dgettext('wombat', 'Jamaica'), 'jo'=> patI18n::dgettext('wombat', 'Jordan'), 'jp'=> patI18n::dgettext('wombat', 'Japan'), 'ke'=> patI18n::dgettext('wombat', 'Kenya'), 'kg'=> patI18n::dgettext('wombat', 'Kyrgyzstan'), 'kh'=> patI18n::dgettext('wombat', 'Cambodia'), 'ki'=> patI18n::dgettext('wombat', 'Kiribati'), 'km'=> patI18n::dgettext('wombat', 'Comoros'), 'kn'=> patI18n::dgettext('wombat', 'Saint Kitts and Nevis'), 'kp'=> patI18n::dgettext('wombat', 'Korea, Democratic People\'s Republic of'), 'kr'=> patI18n::dgettext('wombat', 'Korea, Republic of'), 'kw'=> patI18n::dgettext('wombat', 'Kuwait'), 'ky'=> patI18n::dgettext('wombat', 'Cayman Islands'), 'kz'=> patI18n::dgettext('wombat', 'Kazakhstan'), 'la'=> patI18n::dgettext('wombat', 'Laos'), 'lb'=> patI18n::dgettext('wombat', 'Lebanon'), 'lc'=> patI18n::dgettext('wombat', 'Saint Lucia'), 'li'=> patI18n::dgettext('wombat', 'Liechtenstein'), 'lk'=> patI18n::dgettext('wombat', 'Sri Lanka'), 'lr'=> patI18n::dgettext('wombat', 'Liberia'), 'ls'=> patI18n::dgettext('wombat', 'Lesotho'), 'lt'=> patI18n::dgettext('wombat', 'Lithuania'), 'lu'=> patI18n::dgettext('wombat', 'Luxembourg'), 'lv'=> patI18n::dgettext('wombat', 'Latvia'), 'ma'=> patI18n::dgettext('wombat', 'Morocco'), 'mc'=> patI18n::dgettext('wombat', 'Monaco'), 'md'=> patI18n::dgettext('wombat', 'Moldova'), 'mf'=> patI18n::dgettext('wombat', 'Saint Martin (French part)'), 'mg'=> patI18n::dgettext('wombat', 'Madagascar'), 'mh'=> patI18n::dgettext('wombat', 'Marshall Islands'), 'mk'=> patI18n::dgettext('wombat', 'Macedonia'), 'ml'=> patI18n::dgettext('wombat', 'Mali'), 'mm'=> patI18n::dgettext('wombat', 'Myanmar'), 'mn'=> patI18n::dgettext('wombat', 'Mongolia'), 'mo'=> patI18n::dgettext('wombat', 'Macao'), 'mp'=> patI18n::dgettext('wombat', 'Northern Mariana Islands'), 'mq'=> patI18n::dgettext('wombat', 'Martinique'), 'mr'=> patI18n::dgettext('wombat', 'Mauritania'), 'ms'=> patI18n::dgettext('wombat', 'Montserrat'), 'mt'=> patI18n::dgettext('wombat', 'Malta'), 'mu'=> patI18n::dgettext('wombat', 'Mauritius'), 'mv'=> patI18n::dgettext('wombat', 'Maldives'), 'mw'=> patI18n::dgettext('wombat', 'Malawi'), 'mx'=> patI18n::dgettext('wombat', 'Mexico'), 'my'=> patI18n::dgettext('wombat', 'Malaysia'), 'mz'=> patI18n::dgettext('wombat', 'Mozambique'), 'na'=> patI18n::dgettext('wombat', 'Namibia'), 'nc'=> patI18n::dgettext('wombat', 'New Caledonia'), 'ne'=> patI18n::dgettext('wombat', 'Niger'), 'nf'=> patI18n::dgettext('wombat', 'Norfolk Island'), 'ng'=> patI18n::dgettext('wombat', 'Nigeria'), 'ni'=> patI18n::dgettext('wombat', 'Nicaragua'), 'nl'=> patI18n::dgettext('wombat', 'Netherlands'), 'no'=> patI18n::dgettext('wombat', 'Norway'), 'np'=> patI18n::dgettext('wombat', 'Nepal'), 'nr'=> patI18n::dgettext('wombat', 'Nauru'), 'nu'=> patI18n::dgettext('wombat', 'Niue'), 'nz'=> patI18n::dgettext('wombat', 'New Zealand'), 'om'=> patI18n::dgettext('wombat', 'Oman'), 'pa'=> patI18n::dgettext('wombat', 'Panama'), 'pe'=> patI18n::dgettext('wombat', 'Peru'), 'pf'=> patI18n::dgettext('wombat', 'French Polynesia'), 'pg'=> patI18n::dgettext('wombat', 'Papua New Guinea'), 'ph'=> patI18n::dgettext('wombat', 'Philippines'), 'pk'=> patI18n::dgettext('wombat', 'Pakistan'), 'pl'=> patI18n::dgettext('wombat', 'Poland'), 'pm'=> patI18n::dgettext('wombat', 'Saint Pierre and Miquelon'), 'pn'=> patI18n::dgettext('wombat', 'Pitcairn'), 'pr'=> patI18n::dgettext('wombat', 'Puerto Rico'), 'ps'=> patI18n::dgettext('wombat', 'Palestinian Territory, Occupied'), 'pt'=> patI18n::dgettext('wombat', 'Portugal'), 'pw'=> patI18n::dgettext('wombat', 'Palau'), 'py'=> patI18n::dgettext('wombat', 'Paraguay'), 'qa'=> patI18n::dgettext('wombat', 'Qatar'), 're'=> patI18n::dgettext('wombat', 'Reunion'), 'ro'=> patI18n::dgettext('wombat', 'Romania'), 'rs'=> patI18n::dgettext('wombat', 'Serbia'), 'ru'=> patI18n::dgettext('wombat', 'Russian Federation'), 'rw'=> patI18n::dgettext('wombat', 'Rwanda'), 'sa'=> patI18n::dgettext('wombat', 'Saudi Arabia'), 'sb'=> patI18n::dgettext('wombat', 'Solomon Islands'), 'sc'=> patI18n::dgettext('wombat', 'Seychelles'), 'sd'=> patI18n::dgettext('wombat', 'Sudan'), 'se'=> patI18n::dgettext('wombat', 'Sweden'), 'sg'=> patI18n::dgettext('wombat', 'Singapore'), 'sh'=> patI18n::dgettext('wombat', 'Saint Helena'), 'si'=> patI18n::dgettext('wombat', 'Slovenia'), 'sj'=> patI18n::dgettext('wombat', 'Svalbard and Jan Mayen'), 'sk'=> patI18n::dgettext('wombat', 'Slovakia'), 'sl'=> patI18n::dgettext('wombat', 'Sierra Leone'), 'sm'=> patI18n::dgettext('wombat', 'San Marino'), 'sn'=> patI18n::dgettext('wombat', 'Senegal'), 'so'=> patI18n::dgettext('wombat', 'Somalia'), 'sr'=> patI18n::dgettext('wombat', 'Suriname'), 'ss'=> patI18n::dgettext('wombat', 'South Sudan'), 'st'=> patI18n::dgettext('wombat', 'Sao Tome and Principe'), 'sv'=> patI18n::dgettext('wombat', 'El Salvador'), 'sx'=> patI18n::dgettext('wombat', 'Sint Maarten (Dutch part)'), 'sy'=> patI18n::dgettext('wombat', 'Syrian Arab Republic'), 'sz'=> patI18n::dgettext('wombat', 'Swaziland'), 'tc'=> patI18n::dgettext('wombat', 'Turks and Caicos Islands'), 'td'=> patI18n::dgettext('wombat', 'Chad'), 'tf'=> patI18n::dgettext('wombat', 'French Southern Territories'), 'tg'=> patI18n::dgettext('wombat', 'Togo'), 'th'=> patI18n::dgettext('wombat', 'Thailand'), 'tj'=> patI18n::dgettext('wombat', 'Tajikistan'), 'tk'=> patI18n::dgettext('wombat', 'Tokelau'), 'tl'=> patI18n::dgettext('wombat', 'Timor-Leste'), 'tm'=> patI18n::dgettext('wombat', 'Turkmenistan'), 'tn'=> patI18n::dgettext('wombat', 'Tunisia'), 'to'=> patI18n::dgettext('wombat', 'Tonga'), // 'tp'=> patI18n::dgettext('wombat', 'East Timor'), // transitionally reserved 'tr'=> patI18n::dgettext('wombat', 'Turkey'), 'tt'=> patI18n::dgettext('wombat', 'Trinidad and Tobago'), 'tv'=> patI18n::dgettext('wombat', 'Tuvalu'), 'tw'=> patI18n::dgettext('wombat', 'Taiwan'), 'tz'=> patI18n::dgettext('wombat', 'Tanzania'), 'ua'=> patI18n::dgettext('wombat', 'Ukraine'), 'ug'=> patI18n::dgettext('wombat', 'Uganda'), 'um'=> patI18n::dgettext('wombat', 'United States Minor Outlying Islands'), 'us'=> patI18n::dgettext('wombat', 'United States'), 'uy'=> patI18n::dgettext('wombat', 'Uruguay'), 'uz'=> patI18n::dgettext('wombat', 'Uzbekistan'), 'va'=> patI18n::dgettext('wombat', 'Vatican City State'), 'vc'=> patI18n::dgettext('wombat', 'Saint Vincent and The Grenadines'), 've'=> patI18n::dgettext('wombat', 'Venezuela'), 'vg'=> patI18n::dgettext('wombat', 'Virgin Islands (British)'), 'vi'=> patI18n::dgettext('wombat', 'Virgin Islands (U.S.)'), 'vn'=> patI18n::dgettext('wombat', 'Viet Nam'), 'vu'=> patI18n::dgettext('wombat', 'Vanuatu'), 'wf'=> patI18n::dgettext('wombat', 'Wallis And Futuna Islands'), 'ws'=> patI18n::dgettext('wombat', 'Samoa'), 'ye'=> patI18n::dgettext('wombat', 'Yemen'), 'yt'=> patI18n::dgettext('wombat', 'Mayotte'), // 'yu'=> patI18n::dgettext('wombat', 'Yugoslavia'), // transitionally reserved 'za'=> patI18n::dgettext('wombat', 'South Africa'), 'zm'=> patI18n::dgettext('wombat', 'Zambia'), // 'zr'=> patI18n::dgettext('wombat', 'Zaire'), // transitionally reserved 'zw'=> patI18n::dgettext('wombat', 'Zimbabwe') ); natsort(self::$list); } /** * find entry in dictionary * * In country code dictionary, this is just the reverse mapping from * localized country name to code - seldomly used * * @param array $data * @return array|null */ protected function find($data) { $word = strtolower(trim($data['name'])); foreach (self::$list as $id => $name) { if ($word == strtolower(trim($name))) { $data = array( 'populated' => true, 'id' => $id, 'countrycode' => $id, 'countryname' => $name ); return $data; } } return null; } /** * load record by id * * Map code to name * * @param string $id */ public function load($id) { $id = strtolower($id); if ('c' == $id) { $id = 'us'; } if ($this->id == $id) { return; } if (!isset(self::$list[$id])) { WBClass::load('WBException_Argument'); throw new WBException_Argument('Invalid country code: "'.$id.'"!', 1, __CLASS__); } $this->id = $id; $this->word = self::$list[$id]; $this->data = array( 'populated' => true, 'id' => $id, 'countrycode' => $id, 'countryname' => $this->word ); } /** * extract dictionary data from word * * Just to satify the interface * * @see include/WB/WBDictionary#explode() * @param string $word * @return array */ protected function explode($word) { return array('name' => $word); } /** * add record to dictionary * * This is just a fake. Insert is not allowed * * @see include/WB/WBDictionary#insert() * @param array record to save * @return string record id */ protected function insert($data) { return null; } /** * save additional data to dictionary record * * This is just a fake - merge is not required * * @see populate() * @see $mergeFields * @param array $data * @return array */ protected function merge($save) { return $save; } /** * automatical populate function * * Surf to URL and extract title, description as well as * * @param string $id * @see include/WB/WBDictionary#autoPolulate() */ public function autoPopulate($id = null) { } /** * get list of dictionary records * * Get all countries * * @return array $list */ public function getList() { return self::$list; } } ?>