2 # Locale::Country - ISO codes for country identification (ISO 3166)
4 # $Id: Country.pm,v 2.1 2002/02/06 04:07:09 neilb Exp $
7 package Locale::Country;
13 use Locale::Constants;
16 #-----------------------------------------------------------------------
17 # Public Global Variables
18 #-----------------------------------------------------------------------
19 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
20 $VERSION = sprintf("%d.%02d", q$Revision: 2.1 $ =~ /(\d+)\.(\d+)/);
22 @EXPORT = qw(code2country country2code
23 all_country_codes all_country_names
25 LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 LOCALE_CODE_NUMERIC);
27 #-----------------------------------------------------------------------
28 # Private Global Variables
29 #-----------------------------------------------------------------------
34 #=======================================================================
36 # code2country ( CODE [, CODESET ] )
38 #=======================================================================
42 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
45 return undef unless defined $code;
47 #-------------------------------------------------------------------
48 # Make sure the code is in the right form before we use it
49 # to look up the corresponding country.
50 # We have to sprintf because the codes are given as 3-digits,
51 # with leading 0's. Eg 052 for Barbados.
52 #-------------------------------------------------------------------
53 if ($codeset == LOCALE_CODE_NUMERIC)
55 return undef if ($code =~ /\D/);
56 $code = sprintf("%.3d", $code);
63 if (exists $CODES->[$codeset]->{$code})
65 return $CODES->[$codeset]->{$code};
69 #---------------------------------------------------------------
70 # no such country code!
71 #---------------------------------------------------------------
77 #=======================================================================
79 # country2code ( NAME [, CODESET ] )
81 #=======================================================================
85 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
88 return undef unless defined $country;
89 $country = lc($country);
90 if (exists $COUNTRIES->[$codeset]->{$country})
92 return $COUNTRIES->[$codeset]->{$country};
96 #---------------------------------------------------------------
98 #---------------------------------------------------------------
104 #=======================================================================
106 # country_code2code ( NAME [, CODESET ] )
108 #=======================================================================
109 sub country_code2code
111 (@_ == 3) or croak "country_code2code() takes 3 arguments!";
120 return undef if $inset == $outset;
121 $country = code2country($code, $inset);
122 return undef if not defined $country;
123 $outcode = country2code($country, $outset);
128 #=======================================================================
130 # all_country_codes ( [ CODESET ] )
132 #=======================================================================
133 sub all_country_codes
135 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
137 return keys %{ $CODES->[$codeset] };
141 #=======================================================================
143 # all_country_names ( [ CODESET ] )
145 #=======================================================================
146 sub all_country_names
148 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
150 return values %{ $CODES->[$codeset] };
154 #=======================================================================
156 # _alias_code ( ALIAS => CODE [ , CODESET ] )
158 # Add an alias for an existing code. If the CODESET isn't specified,
159 # then we use the default (currently the alpha-2 codeset).
161 # Locale::Country::_alias_code('uk' => 'gb');
163 #=======================================================================
168 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
173 if (not exists $CODES->[$codeset]->{$real})
175 carp "attempt to alias \"$alias\" to unknown country code \"$real\"\n";
178 $country = $CODES->[$codeset]->{$real};
179 $CODES->[$codeset]->{$alias} = $country;
180 $COUNTRIES->[$codeset]->{"\L$country"} = $alias;
186 #=======================================================================
188 # initialisation code - stuff the DATA into the ALPHA2 hash
190 #=======================================================================
192 my ($alpha2, $alpha3, $numeric);
193 my ($country, @countries);
200 ($alpha2, $alpha3, $numeric, @countries) = split(/:/, $_);
202 $CODES->[LOCALE_CODE_ALPHA_2]->{$alpha2} = $countries[0];
203 foreach $country (@countries)
205 $COUNTRIES->[LOCALE_CODE_ALPHA_2]->{"\L$country"} = $alpha2;
210 $CODES->[LOCALE_CODE_ALPHA_3]->{$alpha3} = $countries[0];
211 foreach $country (@countries)
213 $COUNTRIES->[LOCALE_CODE_ALPHA_3]->{"\L$country"} = $alpha3;
219 $CODES->[LOCALE_CODE_NUMERIC]->{$numeric} = $countries[0];
220 foreach $country (@countries)
222 $COUNTRIES->[LOCALE_CODE_NUMERIC]->{"\L$country"} = $numeric;
233 ae:are:784:United Arab Emirates
234 af:afg:004:Afghanistan
235 ag:atg:028:Antigua and Barbuda
239 an:ant:530:Netherlands Antilles
243 as:asm:016:American Samoa
247 az:aze:031:Azerbaijan
248 ba:bih:070:Bosnia and Herzegovina
250 bd:bgd:050:Bangladesh
252 bf:bfa:854:Burkina Faso
258 bn:brn:096:Brunei Darussalam
268 cc:::Cocos (Keeling) Islands
269 cd:cod:180:Congo, The Democratic Republic of the:Congo, Democratic Republic of the
270 cf:caf:140:Central African Republic
272 ch:che:756:Switzerland
273 ci:civ:384:Cote D'Ivoire
274 ck:cok:184:Cook Islands
279 cr:cri:188:Costa Rica
281 cv:cpv:132:Cape Verde
282 cx:::Christmas Island
284 cz:cze:203:Czech Republic
289 do:dom:214:Dominican Republic
294 eh:esh:732:Western Sahara
300 fk:flk:238:Falkland Islands (Malvinas):Falkland Islands (Islas Malvinas)
301 fm:fsm:583:Micronesia, Federated States of
302 fo:fro:234:Faroe Islands
304 fx:::France, Metropolitan
306 gb:gbr:826:United Kingdom:Great Britain
309 gf:guf:254:French Guiana
315 gp:glp:312:Guadeloupe
316 gq:gnq:226:Equatorial Guinea
318 gs:::South Georgia and the South Sandwich Islands
321 gw:gnb:624:Guinea-Bissau
324 hm:::Heard Island and McDonald Islands
333 io:::British Indian Ocean Territory
335 ir:irn:364:Iran, Islamic Republic of:Iran
342 kg:kgz:417:Kyrgyzstan
346 kn:kna:659:Saint Kitts and Nevis
347 kp:prk:408:Korea, Democratic People's Republic of:Korea, North:North Korea
348 kr:kor:410:Korea, Republic of:Korea, South:South Korea
350 ky:cym:136:Cayman Islands
352 la:lao:418:Lao People's Democratic Republic
354 lc:lca:662:Saint Lucia
355 li:lie:438:Liechtenstein
360 lu:lux:442:Luxembourg
362 ly:lby:434:Libyan Arab Jamahiriya:Libya
365 md:mda:498:Moldova, Republic of
366 mg:mdg:450:Madagascar
367 mh:mhl:584:Marshall Islands
368 mk:mkd:807:Macedonia, the Former Yugoslav Republic of:Macedonia, Former Yugoslav Republic of:Macedonia
373 mp:mnp:580:Northern Mariana Islands
374 mq:mtq:474:Martinique
375 mr:mrt:478:Mauritania
376 ms:msr:500:Montserrat
383 mz:moz:508:Mozambique
385 nc:ncl:540:New Caledonia
387 nf:nfk:574:Norfolk Island
390 nl:nld:528:Netherlands
395 nz:nzl:554:New Zealand
399 pf:pyf:258:French Polynesia
400 pg:png:598:Papua New Guinea
401 ph:phl:608:Philippines
404 pm:spm:666:Saint Pierre and Miquelon
405 pn:pcn:612:Pitcairn:Pitcairn Island
406 pr:pri:630:Puerto Rico
407 ps:pse:275:Palestinian Territory, Occupied
414 ru:rus:643:Russian Federation:Russia
416 sa:sau:682:Saudi Arabia
417 sb:slb:090:Solomon Islands
418 sc:syc:690:Seychelles
422 sh:shn:654:Saint Helena
424 sj:sjm:744:Svalbard and Jan Mayen:Jan Mayen:Svalbard
426 sl:sle:694:Sierra Leone
427 sm:smr:674:San Marino
431 st:stp:678:Sao Tome and Principe
432 sv:slv:222:El Salvador
433 sy:syr:760:Syrian Arab Republic:Syria
435 tc:tca:796:Turks and Caicos Islands
437 tf:::French Southern Territories
440 tj:tjk:762:Tajikistan
442 tm:tkm:795:Turkmenistan
445 tp:tmp:626:East Timor
447 tt:tto:780:Trinidad and Tobago
449 tw:twn:158:Taiwan, Province of China:Taiwan
450 tz:tza:834:Tanzania, United Republic of:Tanzania
453 um:::United States Minor Outlying Islands
454 us:usa:840:United States:USA:United States of America
456 uz:uzb:860:Uzbekistan
457 va:vat:336:Holy See (Vatican City State):Hole See (Vatican City)
458 vc:vct:670:Saint Vincent and the Grenadines
460 vg:vgb:092:Virgin Islands, British:British Virgin Islands
461 vi:vir:850:Virgin Islands, U.S.
464 wf:wlf:876:Wallis and Futuna
468 yu:yug:891:Yugoslavia
469 za:zaf:710:South Africa