# Locale::Country - ISO codes for country identification (ISO 3166)
# $Id: Country.pm,v 2.7 2004/06/10 21:19:34 neilb Exp $
#-----------------------------------------------------------------------
# Public Global Variables
#-----------------------------------------------------------------------
use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK);
$VERSION = sprintf("%d.%02d", q$Revision: 2.7 $ =~ /(\d+)\.(\d+)/);
@EXPORT = qw(code2country country2code
all_country_codes all_country_names
LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 LOCALE_CODE_NUMERIC);
#-----------------------------------------------------------------------
# Private Global Variables
#-----------------------------------------------------------------------
#=======================================================================
# code2country ( CODE [, CODESET ] )
#=======================================================================
my $codeset = @_ > 0 ?
shift : LOCALE_CODE_DEFAULT
;
return undef unless defined $code;
#-------------------------------------------------------------------
# Make sure the code is in the right form before we use it
# to look up the corresponding country.
# We have to sprintf because the codes are given as 3-digits,
# with leading 0's. Eg 052 for Barbados.
#-------------------------------------------------------------------
if ($codeset == LOCALE_CODE_NUMERIC
)
return undef if ($code =~ /\D/);
$code = sprintf("%.3d", $code);
if (exists $CODES->[$codeset]->{$code})
return $CODES->[$codeset]->{$code};
#---------------------------------------------------------------
#---------------------------------------------------------------
#=======================================================================
# country2code ( NAME [, CODESET ] )
#=======================================================================
my $codeset = @_ > 0 ?
shift : LOCALE_CODE_DEFAULT
;
return undef unless defined $country;
if (exists $COUNTRIES->[$codeset]->{$country})
return $COUNTRIES->[$codeset]->{$country};
#---------------------------------------------------------------
#---------------------------------------------------------------
#=======================================================================
# country_code2code ( NAME [, CODESET ] )
#=======================================================================
(@_ == 3) or croak
"country_code2code() takes 3 arguments!";
return undef if $inset == $outset;
$country = code2country
($code, $inset);
return undef if not defined $country;
$outcode = country2code
($country, $outset);
#=======================================================================
# all_country_codes ( [ CODESET ] )
#=======================================================================
my $codeset = @_ > 0 ?
shift : LOCALE_CODE_DEFAULT
;
return keys %{ $CODES->[$codeset] };
#=======================================================================
# all_country_names ( [ CODESET ] )
#=======================================================================
my $codeset = @_ > 0 ?
shift : LOCALE_CODE_DEFAULT
;
return values %{ $CODES->[$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');
#=======================================================================
my $codeset = @_ > 0 ?
shift : LOCALE_CODE_DEFAULT
;
if (not exists $CODES->[$codeset]->{$real})
carp
"attempt to alias \"$alias\" to unknown country code \"$real\"\n";
$country = $CODES->[$codeset]->{$real};
$CODES->[$codeset]->{$alias} = $country;
$COUNTRIES->[$codeset]->{"\L$country"} = $alias;
# old name of function for backwards compatibility
*_alias_code
= *alias_code
;
#=======================================================================
# change the official name for a country, eg:
# rather than the standard 'United Kingdom'. The original is retained
# as an alias, but the new name will be returned if you lookup the
#=======================================================================
my $codeset = @_ > 0 ?
shift : _code2codeset
($code);
if (not defined $codeset)
carp
"rename_country(): unknown country code \"$code\"\n";
$country = $CODES->[$codeset]->{$code};
foreach my $cset (LOCALE_CODE_ALPHA_2
,
$c = country_code2code
($code, $codeset, $cset);
$CODES->[$cset]->{$c} = $new_name;
$COUNTRIES->[$cset]->{"\L$new_name"} = $c;
#=======================================================================
# given a country code in an unknown codeset, return the codeset
#=======================================================================
foreach my $codeset (LOCALE_CODE_ALPHA_2
, LOCALE_CODE_ALPHA_3
,
return $codeset if (exists $CODES->[$codeset]->{$code})
#=======================================================================
# initialisation code - stuff the DATA into the ALPHA2 hash
#=======================================================================
my ($alpha2, $alpha3, $numeric);
my ($country, @countries);
($alpha2, $alpha3, $numeric, @countries) = split(/:/, $_);
$CODES->[LOCALE_CODE_ALPHA_2
]->{$alpha2} = $countries[0];
foreach $country (@countries)
$COUNTRIES->[LOCALE_CODE_ALPHA_2
]->{"\L$country"} = $alpha2;
$CODES->[LOCALE_CODE_ALPHA_3
]->{$alpha3} = $countries[0];
foreach $country (@countries)
$COUNTRIES->[LOCALE_CODE_ALPHA_3
]->{"\L$country"} = $alpha3;
$CODES->[LOCALE_CODE_NUMERIC
]->{$numeric} = $countries[0];
foreach $country (@countries)
$COUNTRIES->[LOCALE_CODE_NUMERIC
]->{"\L$country"} = $numeric;
ae
:are
:784:United Arab Emirates
ag
:atg
:028:Antigua
and Barbuda
an
:ant
:530:Netherlands Antilles
as
:asm
:016:American Samoa
ba
:bih
:070:Bosnia
and Herzegovina
bn
:brn
:096:Brunei Darussalam
cc
:cck
:166:Cocos
(Keeling
) Islands
cd
:cod
:180:Congo
, The Democratic Republic of the
:Zaire
:Congo
, Democratic Republic of the
cf
:caf
:140:Central African Republic
cg
:cog
:178:Congo
:Congo
, Republic of the
cs:scg:891:Serbia and Montenegro:Yugoslavia
cx:cxr:162:Christmas Island
cz:cze:203:Czech Republic
do:dom:214:Dominican Republic
eh:esh:732:Western Sahara
fk:flk:238:Falkland Islands (Malvinas):Falkland Islands (Islas Malvinas)
fm:fsm:583:Micronesia, Federated States of
fx:fxx:249:France, Metropolitan
gb:gbr:826:United Kingdom:Great Britain
gq:gnq:226:Equatorial Guinea
gs:sgs:239:South Georgia and the South Sandwich Islands
hm:hmd:334:Heard Island and McDonald Islands
io:iot:086:British Indian Ocean Territory
ir:irn:364:Iran, Islamic Republic of:Iran
kn:kna:659:Saint Kitts and Nevis
kp:prk:408:Korea, Democratic People's Republic of
:Korea
, North
:North Korea
kr
:kor
:410:Korea
, Republic of
:Korea
, South
:South Korea
ky
:cym
:136:Cayman Islands
kz
:kaz
:398:Kazakhstan
:Kazakstan
la
:lao
:418:Lao People
's Democratic Republic
ly:lby:434:Libyan Arab Jamahiriya:Libya
md:mda:498:Moldova, Republic of:Moldova
mh:mhl:584:Marshall Islands
mk:mkd:807:Macedonia, the Former Yugoslav Republic of:Macedonia, Former Yugoslav Republic of:Macedonia
mp:mnp:580:Northern Mariana Islands
nf:nfk:574:Norfolk Island
pf:pyf:258:French Polynesia
pg:png:598:Papua New Guinea
pm:spm:666:Saint Pierre and Miquelon
pn:pcn:612:Pitcairn:Pitcairn Island
ps:pse:275:Palestinian Territory, Occupied
ru:rus:643:Russian Federation:Russia
sb:slb:090:Solomon Islands
sj:sjm:744:Svalbard and Jan Mayen:Jan Mayen:Svalbard
st:stp:678:Sao Tome and Principe
sy:syr:760:Syrian Arab Republic:Syria
tc:tca:796:Turks and Caicos Islands
tf:atf:260:French Southern Territories:French Southern and Antarctic Lands
tl:tls:626:Timor-Leste:East Timor
tt:tto:780:Trinidad and Tobago
tw:twn:158:Taiwan, Province of China:Taiwan
tz:tza:834:Tanzania, United Republic of:Tanzania
um:umi:581:United States Minor Outlying Islands
us:usa:840:United States:USA:United States of America
va:vat:336:Holy See (Vatican City State):Holy See (Vatican City)
vc:vct:670:Saint Vincent and the Grenadines
vg:vgb:092:Virgin Islands, British:British Virgin Islands
vi:vir:850:Virgin Islands, U.S.
wf:wlf:876:Wallis and Futuna