#
# Locale::Country - ISO codes for country identification (ISO 3166)
#
-# $Id: Country.pm,v 2.1 2002/02/06 04:07:09 neilb Exp $
+# $Id: Country.pm,v 2.6 2002/07/10 16:33:27 neilb Exp $
#
package Locale::Country;
# Public Global Variables
#-----------------------------------------------------------------------
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
-$VERSION = sprintf("%d.%02d", q$Revision: 2.1 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 2.61 $ =~ /(\d+)\.(\d+)/);
@ISA = qw(Exporter);
@EXPORT = qw(code2country country2code
all_country_codes all_country_names
#=======================================================================
#
-# _alias_code ( ALIAS => CODE [ , CODESET ] )
+# alias_code ( ALIAS => CODE [ , CODESET ] )
#
# Add an alias for an existing code. If the CODESET isn't specified,
# then we use the default (currently the alpha-2 codeset).
#
-# Locale::Country::_alias_code('uk' => 'gb');
+# Locale::Country::alias_code('uk' => 'gb');
#
#=======================================================================
-sub _alias_code
+sub alias_code
{
my $alias = shift;
my $real = shift;
return $alias;
}
+# old name of function for backwards compatibility
+*_alias_code = *alias_code;
+
+
+#=======================================================================
+#
+# rename_country
+#
+# change the official name for a country, eg:
+# gb => 'Great Britain'
+# rather than the standard 'United Kingdom'. The original is retained
+# as an alias, but the new name will be returned if you lookup the
+# name from code.
+#
+#=======================================================================
+sub rename_country
+{
+ my $code = shift;
+ my $new_name = shift;
+ my $codeset = @_ > 0 ? shift : _code2codeset($code);
+ my $country;
+ my $c;
+
+
+ if (not defined $codeset)
+ {
+ carp "rename_country(): unknown country code \"$code\"\n";
+ return 0;
+ }
+
+ $country = $CODES->[$codeset]->{$code};
+
+ foreach my $cset (LOCALE_CODE_ALPHA_2,
+ LOCALE_CODE_ALPHA_3,
+ LOCALE_CODE_NUMERIC)
+ {
+ if ($cset == $codeset)
+ {
+ $c = $code;
+ }
+ else
+ {
+ $c = country_code2code($code, $codeset, $cset);
+ }
+
+ $CODES->[$cset]->{$c} = $new_name;
+ $COUNTRIES->[$cset]->{"\L$new_name"} = $c;
+ }
+
+ return 1;
+}
+
+
+#=======================================================================
+#
+# _code2codeset
+#
+# given a country code in an unknown codeset, return the codeset
+# it is from, or undef.
+#
+#=======================================================================
+sub _code2codeset
+{
+ my $code = shift;
+
+
+ foreach my $codeset (LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3,
+ LOCALE_CODE_NUMERIC)
+ {
+ return $codeset if (exists $CODES->[$codeset]->{$code})
+ }
+
+ return undef;
+}
+
#=======================================================================
#
my ($alpha2, $alpha3, $numeric);
my ($country, @countries);
+ local $_;
while (<DATA>)
{
}
}
+
+ close(DATA);
}
1;
am:arm:051:Armenia
an:ant:530:Netherlands Antilles
ao:ago:024:Angola
-aq:::Antarctica
+aq:ata:010:Antarctica
ar:arg:032:Argentina
as:asm:016:American Samoa
at:aut:040:Austria
br:bra:076:Brazil
bs:bhs:044:Bahamas
bt:btn:064:Bhutan
-bv:::Bouvet Island
+bv:bvt:074:Bouvet Island
bw:bwa:072:Botswana
by:blr:112:Belarus
bz:blz:084:Belize
ca:can:124:Canada
-cc:::Cocos (Keeling) Islands
-cd:cod:180:Congo, The Democratic Republic of the:Congo, Democratic Republic of the
+cc:cck:166:Cocos (Keeling) Islands
cf:caf:140:Central African Republic
-cg:cog:178:Congo
+cg:cog:178:Congo:Congo, Republic of the
ch:che:756:Switzerland
ci:civ:384:Cote D'Ivoire
ck:cok:184:Cook Islands
cr:cri:188:Costa Rica
cu:cub:192:Cuba
cv:cpv:132:Cape Verde
-cx:::Christmas Island
+cx:cxr:162:Christmas Island
cy:cyp:196:Cyprus
cz:cze:203:Czech Republic
de:deu:276:Germany
fm:fsm:583:Micronesia, Federated States of
fo:fro:234:Faroe Islands
fr:fra:250:France
-fx:::France, Metropolitan
+fx:fxx:249:France, Metropolitan
ga:gab:266:Gabon
gb:gbr:826:United Kingdom:Great Britain
gd:grd:308:Grenada
gp:glp:312:Guadeloupe
gq:gnq:226:Equatorial Guinea
gr:grc:300:Greece
-gs:::South Georgia and the South Sandwich Islands
+gs:sgs:239:South Georgia and the South Sandwich Islands
gt:gtm:320:Guatemala
gu:gum:316:Guam
gw:gnb:624:Guinea-Bissau
gy:guy:328:Guyana
hk:hkg:344:Hong Kong
-hm:::Heard Island and McDonald Islands
+hm:hmd:334:Heard Island and McDonald Islands
hn:hnd:340:Honduras
hr:hrv:191:Croatia
ht:hti:332:Haiti
ie:irl:372:Ireland
il:isr:376:Israel
in:ind:356:India
-io:::British Indian Ocean Territory
+io:iot:086:British Indian Ocean Territory
iq:irq:368:Iraq
ir:irn:364:Iran, Islamic Republic of:Iran
is:isl:352:Iceland
kr:kor:410:Korea, Republic of:Korea, South:South Korea
kw:kwt:414:Kuwait
ky:cym:136:Cayman Islands
-kz:kaz:398:Kazakstan
+kz:kaz:398:Kazakhstan:Kazakstan
la:lao:418:Lao People's Democratic Republic
lb:lbn:422:Lebanon
lc:lca:662:Saint Lucia
ly:lby:434:Libyan Arab Jamahiriya:Libya
ma:mar:504:Morocco
mc:mco:492:Monaco
-md:mda:498:Moldova, Republic of
+md:mda:498:Moldova, Republic of:Moldova
mg:mdg:450:Madagascar
mh:mhl:584:Marshall Islands
mk:mkd:807:Macedonia, the Former Yugoslav Republic of:Macedonia, Former Yugoslav Republic of:Macedonia
ml:mli:466:Mali
mm:mmr:104:Myanmar
mn:mng:496:Mongolia
-mo:mac:446:Macau
+mo:mac:446:Macao:Macau
mp:mnp:580:Northern Mariana Islands
mq:mtq:474:Martinique
mr:mrt:478:Mauritania
sz:swz:748:Swaziland
tc:tca:796:Turks and Caicos Islands
td:tcd:148:Chad
-tf:::French Southern Territories
+tf:atf:260:French Southern Territories
tg:tgo:768:Togo
th:tha:764:Thailand
tj:tjk:762:Tajikistan
tm:tkm:795:Turkmenistan
tn:tun:788:Tunisia
to:ton:776:Tonga
-tp:tmp:626:East Timor
+tl:tls:626:East Timor
tr:tur:792:Turkey
tt:tto:780:Trinidad and Tobago
tv:tuv:798:Tuvalu
tz:tza:834:Tanzania, United Republic of:Tanzania
ua:ukr:804:Ukraine
ug:uga:800:Uganda
-um:::United States Minor Outlying Islands
+um:umi:581:United States Minor Outlying Islands
us:usa:840:United States:USA:United States of America
uy:ury:858:Uruguay
uz:uzb:860:Uzbekistan
-va:vat:336:Holy See (Vatican City State):Hole See (Vatican City)
+va:vat:336:Holy See (Vatican City State):Holy See (Vatican City)
vc:vct:670:Saint Vincent and the Grenadines
ve:ven:862:Venezuela
vg:vgb:092:Virgin Islands, British:British Virgin Islands
wf:wlf:876:Wallis and Futuna
ws:wsm:882:Samoa
ye:yem:887:Yemen
-yt:::Mayotte
+yt:myt:175:Mayotte
yu:yug:891:Yugoslavia
za:zaf:710:South Africa
zm:zmb:894:Zambia
-zr:::Zaire
+zr:zar:180:Zaire:Congo, The Democratic Republic of the:Congo, Democratic Republic of the
zw:zwe:716:Zimbabwe