1N/A#
1N/A# Locale::Country - ISO codes for country identification (ISO 3166)
1N/A#
1N/A# $Id: Country.pm,v 2.6 2002/07/10 16:33:27 neilb Exp $
1N/A#
1N/A
1N/Apackage Locale::Country;
1N/Ause strict;
1N/Arequire 5.002;
1N/A
1N/Arequire Exporter;
1N/Ause Carp;
1N/Ause Locale::Constants;
1N/A
1N/A
1N/A#-----------------------------------------------------------------------
1N/A# Public Global Variables
1N/A#-----------------------------------------------------------------------
1N/Ause vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
1N/A$VERSION = sprintf("%d.%02d", q$Revision: 2.61 $ =~ /(\d+)\.(\d+)/);
1N/A@ISA = qw(Exporter);
1N/A@EXPORT = qw(code2country country2code
1N/A all_country_codes all_country_names
1N/A country_code2code
1N/A LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 LOCALE_CODE_NUMERIC);
1N/A
1N/A#-----------------------------------------------------------------------
1N/A# Private Global Variables
1N/A#-----------------------------------------------------------------------
1N/Amy $CODES = [];
1N/Amy $COUNTRIES = [];
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# code2country ( CODE [, CODESET ] )
1N/A#
1N/A#=======================================================================
1N/Asub code2country
1N/A{
1N/A my $code = shift;
1N/A my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
1N/A
1N/A
1N/A return undef unless defined $code;
1N/A
1N/A #-------------------------------------------------------------------
1N/A # Make sure the code is in the right form before we use it
1N/A # to look up the corresponding country.
1N/A # We have to sprintf because the codes are given as 3-digits,
1N/A # with leading 0's. Eg 052 for Barbados.
1N/A #-------------------------------------------------------------------
1N/A if ($codeset == LOCALE_CODE_NUMERIC)
1N/A {
1N/A return undef if ($code =~ /\D/);
1N/A $code = sprintf("%.3d", $code);
1N/A }
1N/A else
1N/A {
1N/A $code = lc($code);
1N/A }
1N/A
1N/A if (exists $CODES->[$codeset]->{$code})
1N/A {
1N/A return $CODES->[$codeset]->{$code};
1N/A }
1N/A else
1N/A {
1N/A #---------------------------------------------------------------
1N/A # no such country code!
1N/A #---------------------------------------------------------------
1N/A return undef;
1N/A }
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# country2code ( NAME [, CODESET ] )
1N/A#
1N/A#=======================================================================
1N/Asub country2code
1N/A{
1N/A my $country = shift;
1N/A my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
1N/A
1N/A
1N/A return undef unless defined $country;
1N/A $country = lc($country);
1N/A if (exists $COUNTRIES->[$codeset]->{$country})
1N/A {
1N/A return $COUNTRIES->[$codeset]->{$country};
1N/A }
1N/A else
1N/A {
1N/A #---------------------------------------------------------------
1N/A # no such country!
1N/A #---------------------------------------------------------------
1N/A return undef;
1N/A }
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# country_code2code ( NAME [, CODESET ] )
1N/A#
1N/A#=======================================================================
1N/Asub country_code2code
1N/A{
1N/A (@_ == 3) or croak "country_code2code() takes 3 arguments!";
1N/A
1N/A my $code = shift;
1N/A my $inset = shift;
1N/A my $outset = shift;
1N/A my $outcode;
1N/A my $country;
1N/A
1N/A
1N/A return undef if $inset == $outset;
1N/A $country = code2country($code, $inset);
1N/A return undef if not defined $country;
1N/A $outcode = country2code($country, $outset);
1N/A return $outcode;
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# all_country_codes ( [ CODESET ] )
1N/A#
1N/A#=======================================================================
1N/Asub all_country_codes
1N/A{
1N/A my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
1N/A
1N/A return keys %{ $CODES->[$codeset] };
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# all_country_names ( [ CODESET ] )
1N/A#
1N/A#=======================================================================
1N/Asub all_country_names
1N/A{
1N/A my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
1N/A
1N/A return values %{ $CODES->[$codeset] };
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# alias_code ( ALIAS => CODE [ , CODESET ] )
1N/A#
1N/A# Add an alias for an existing code. If the CODESET isn't specified,
1N/A# then we use the default (currently the alpha-2 codeset).
1N/A#
1N/A# Locale::Country::alias_code('uk' => 'gb');
1N/A#
1N/A#=======================================================================
1N/Asub alias_code
1N/A{
1N/A my $alias = shift;
1N/A my $real = shift;
1N/A my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
1N/A
1N/A my $country;
1N/A
1N/A
1N/A if (not exists $CODES->[$codeset]->{$real})
1N/A {
1N/A carp "attempt to alias \"$alias\" to unknown country code \"$real\"\n";
1N/A return undef;
1N/A }
1N/A $country = $CODES->[$codeset]->{$real};
1N/A $CODES->[$codeset]->{$alias} = $country;
1N/A $COUNTRIES->[$codeset]->{"\L$country"} = $alias;
1N/A
1N/A return $alias;
1N/A}
1N/A
1N/A# old name of function for backwards compatibility
1N/A*_alias_code = *alias_code;
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# rename_country
1N/A#
1N/A# change the official name for a country, eg:
1N/A# gb => 'Great Britain'
1N/A# rather than the standard 'United Kingdom'. The original is retained
1N/A# as an alias, but the new name will be returned if you lookup the
1N/A# name from code.
1N/A#
1N/A#=======================================================================
1N/Asub rename_country
1N/A{
1N/A my $code = shift;
1N/A my $new_name = shift;
1N/A my $codeset = @_ > 0 ? shift : _code2codeset($code);
1N/A my $country;
1N/A my $c;
1N/A
1N/A
1N/A if (not defined $codeset)
1N/A {
1N/A carp "rename_country(): unknown country code \"$code\"\n";
1N/A return 0;
1N/A }
1N/A
1N/A $country = $CODES->[$codeset]->{$code};
1N/A
1N/A foreach my $cset (LOCALE_CODE_ALPHA_2,
1N/A LOCALE_CODE_ALPHA_3,
1N/A LOCALE_CODE_NUMERIC)
1N/A {
1N/A if ($cset == $codeset)
1N/A {
1N/A $c = $code;
1N/A }
1N/A else
1N/A {
1N/A $c = country_code2code($code, $codeset, $cset);
1N/A }
1N/A
1N/A $CODES->[$cset]->{$c} = $new_name;
1N/A $COUNTRIES->[$cset]->{"\L$new_name"} = $c;
1N/A }
1N/A
1N/A return 1;
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# _code2codeset
1N/A#
1N/A# given a country code in an unknown codeset, return the codeset
1N/A# it is from, or undef.
1N/A#
1N/A#=======================================================================
1N/Asub _code2codeset
1N/A{
1N/A my $code = shift;
1N/A
1N/A
1N/A foreach my $codeset (LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3,
1N/A LOCALE_CODE_NUMERIC)
1N/A {
1N/A return $codeset if (exists $CODES->[$codeset]->{$code})
1N/A }
1N/A
1N/A return undef;
1N/A}
1N/A
1N/A
1N/A#=======================================================================
1N/A#
1N/A# initialisation code - stuff the DATA into the ALPHA2 hash
1N/A#
1N/A#=======================================================================
1N/A{
1N/A my ($alpha2, $alpha3, $numeric);
1N/A my ($country, @countries);
1N/A
1N/A local $_;
1N/A
1N/A while (<DATA>)
1N/A {
1N/A next unless /\S/;
1N/A chop;
1N/A ($alpha2, $alpha3, $numeric, @countries) = split(/:/, $_);
1N/A
1N/A $CODES->[LOCALE_CODE_ALPHA_2]->{$alpha2} = $countries[0];
1N/A foreach $country (@countries)
1N/A {
1N/A $COUNTRIES->[LOCALE_CODE_ALPHA_2]->{"\L$country"} = $alpha2;
1N/A }
1N/A
1N/A if ($alpha3)
1N/A {
1N/A $CODES->[LOCALE_CODE_ALPHA_3]->{$alpha3} = $countries[0];
1N/A foreach $country (@countries)
1N/A {
1N/A $COUNTRIES->[LOCALE_CODE_ALPHA_3]->{"\L$country"} = $alpha3;
1N/A }
1N/A }
1N/A
1N/A if ($numeric)
1N/A {
1N/A $CODES->[LOCALE_CODE_NUMERIC]->{$numeric} = $countries[0];
1N/A foreach $country (@countries)
1N/A {
1N/A $COUNTRIES->[LOCALE_CODE_NUMERIC]->{"\L$country"} = $numeric;
1N/A }
1N/A }
1N/A
1N/A }
1N/A
1N/A close(DATA);
1N/A}
1N/A
1N/A1;
1N/A
1N/A__DATA__
1N/Aad:and:020:Andorra
1N/Aae:are:784:United Arab Emirates
1N/Aaf:afg:004:Afghanistan
1N/Aag:atg:028:Antigua and Barbuda
1N/Aai:aia:660:Anguilla
1N/Aal:alb:008:Albania
1N/Aam:arm:051:Armenia
1N/Aan:ant:530:Netherlands Antilles
1N/Aao:ago:024:Angola
1N/Aaq:ata:010:Antarctica
1N/Aar:arg:032:Argentina
1N/Aas:asm:016:American Samoa
1N/Aat:aut:040:Austria
1N/Aau:aus:036:Australia
1N/Aaw:abw:533:Aruba
1N/Aaz:aze:031:Azerbaijan
1N/Aba:bih:070:Bosnia and Herzegovina
1N/Abb:brb:052:Barbados
1N/Abd:bgd:050:Bangladesh
1N/Abe:bel:056:Belgium
1N/Abf:bfa:854:Burkina Faso
1N/Abg:bgr:100:Bulgaria
1N/Abh:bhr:048:Bahrain
1N/Abi:bdi:108:Burundi
1N/Abj:ben:204:Benin
1N/Abm:bmu:060:Bermuda
1N/Abn:brn:096:Brunei Darussalam
1N/Abo:bol:068:Bolivia
1N/Abr:bra:076:Brazil
1N/Abs:bhs:044:Bahamas
1N/Abt:btn:064:Bhutan
1N/Abv:bvt:074:Bouvet Island
1N/Abw:bwa:072:Botswana
1N/Aby:blr:112:Belarus
1N/Abz:blz:084:Belize
1N/Aca:can:124:Canada
1N/Acc:cck:166:Cocos (Keeling) Islands
1N/Acf:caf:140:Central African Republic
1N/Acg:cog:178:Congo:Congo, Republic of the
1N/Ach:che:756:Switzerland
1N/Aci:civ:384:Cote D'Ivoire
1N/Ack:cok:184:Cook Islands
1N/Acl:chl:152:Chile
1N/Acm:cmr:120:Cameroon
1N/Acn:chn:156:China
1N/Aco:col:170:Colombia
1N/Acr:cri:188:Costa Rica
1N/Acu:cub:192:Cuba
1N/Acv:cpv:132:Cape Verde
1N/Acx:cxr:162:Christmas Island
1N/Acy:cyp:196:Cyprus
1N/Acz:cze:203:Czech Republic
1N/Ade:deu:276:Germany
1N/Adj:dji:262:Djibouti
1N/Adk:dnk:208:Denmark
1N/Adm:dma:212:Dominica
1N/Ado:dom:214:Dominican Republic
1N/Adz:dza:012:Algeria
1N/Aec:ecu:218:Ecuador
1N/Aee:est:233:Estonia
1N/Aeg:egy:818:Egypt
1N/Aeh:esh:732:Western Sahara
1N/Aer:eri:232:Eritrea
1N/Aes:esp:724:Spain
1N/Aet:eth:231:Ethiopia
1N/Afi:fin:246:Finland
1N/Afj:fji:242:Fiji
1N/Afk:flk:238:Falkland Islands (Malvinas):Falkland Islands (Islas Malvinas)
1N/Afm:fsm:583:Micronesia, Federated States of
1N/Afo:fro:234:Faroe Islands
1N/Afr:fra:250:France
1N/Afx:fxx:249:France, Metropolitan
1N/Aga:gab:266:Gabon
1N/Agb:gbr:826:United Kingdom:Great Britain
1N/Agd:grd:308:Grenada
1N/Age:geo:268:Georgia
1N/Agf:guf:254:French Guiana
1N/Agh:gha:288:Ghana
1N/Agi:gib:292:Gibraltar
1N/Agl:grl:304:Greenland
1N/Agm:gmb:270:Gambia
1N/Agn:gin:324:Guinea
1N/Agp:glp:312:Guadeloupe
1N/Agq:gnq:226:Equatorial Guinea
1N/Agr:grc:300:Greece
1N/Ags:sgs:239:South Georgia and the South Sandwich Islands
1N/Agt:gtm:320:Guatemala
1N/Agu:gum:316:Guam
1N/Agw:gnb:624:Guinea-Bissau
1N/Agy:guy:328:Guyana
1N/Ahk:hkg:344:Hong Kong
1N/Ahm:hmd:334:Heard Island and McDonald Islands
1N/Ahn:hnd:340:Honduras
1N/Ahr:hrv:191:Croatia
1N/Aht:hti:332:Haiti
1N/Ahu:hun:348:Hungary
1N/Aid:idn:360:Indonesia
1N/Aie:irl:372:Ireland
1N/Ail:isr:376:Israel
1N/Ain:ind:356:India
1N/Aio:iot:086:British Indian Ocean Territory
1N/Aiq:irq:368:Iraq
1N/Air:irn:364:Iran, Islamic Republic of:Iran
1N/Ais:isl:352:Iceland
1N/Ait:ita:380:Italy
1N/Ajm:jam:388:Jamaica
1N/Ajo:jor:400:Jordan
1N/Ajp:jpn:392:Japan
1N/Ake:ken:404:Kenya
1N/Akg:kgz:417:Kyrgyzstan
1N/Akh:khm:116:Cambodia
1N/Aki:kir:296:Kiribati
1N/Akm:com:174:Comoros
1N/Akn:kna:659:Saint Kitts and Nevis
1N/Akp:prk:408:Korea, Democratic People's Republic of:Korea, North:North Korea
1N/Akr:kor:410:Korea, Republic of:Korea, South:South Korea
1N/Akw:kwt:414:Kuwait
1N/Aky:cym:136:Cayman Islands
1N/Akz:kaz:398:Kazakhstan:Kazakstan
1N/Ala:lao:418:Lao People's Democratic Republic
1N/Alb:lbn:422:Lebanon
1N/Alc:lca:662:Saint Lucia
1N/Ali:lie:438:Liechtenstein
1N/Alk:lka:144:Sri Lanka
1N/Alr:lbr:430:Liberia
1N/Als:lso:426:Lesotho
1N/Alt:ltu:440:Lithuania
1N/Alu:lux:442:Luxembourg
1N/Alv:lva:428:Latvia
1N/Aly:lby:434:Libyan Arab Jamahiriya:Libya
1N/Ama:mar:504:Morocco
1N/Amc:mco:492:Monaco
1N/Amd:mda:498:Moldova, Republic of:Moldova
1N/Amg:mdg:450:Madagascar
1N/Amh:mhl:584:Marshall Islands
1N/Amk:mkd:807:Macedonia, the Former Yugoslav Republic of:Macedonia, Former Yugoslav Republic of:Macedonia
1N/Aml:mli:466:Mali
1N/Amm:mmr:104:Myanmar
1N/Amn:mng:496:Mongolia
1N/Amo:mac:446:Macao:Macau
1N/Amp:mnp:580:Northern Mariana Islands
1N/Amq:mtq:474:Martinique
1N/Amr:mrt:478:Mauritania
1N/Ams:msr:500:Montserrat
1N/Amt:mlt:470:Malta
1N/Amu:mus:480:Mauritius
1N/Amv:mdv:462:Maldives
1N/Amw:mwi:454:Malawi
1N/Amx:mex:484:Mexico
1N/Amy:mys:458:Malaysia
1N/Amz:moz:508:Mozambique
1N/Ana:nam:516:Namibia
1N/Anc:ncl:540:New Caledonia
1N/Ane:ner:562:Niger
1N/Anf:nfk:574:Norfolk Island
1N/Ang:nga:566:Nigeria
1N/Ani:nic:558:Nicaragua
1N/Anl:nld:528:Netherlands
1N/Ano:nor:578:Norway
1N/Anp:npl:524:Nepal
1N/Anr:nru:520:Nauru
1N/Anu:niu:570:Niue
1N/Anz:nzl:554:New Zealand
1N/Aom:omn:512:Oman
1N/Apa:pan:591:Panama
1N/Ape:per:604:Peru
1N/Apf:pyf:258:French Polynesia
1N/Apg:png:598:Papua New Guinea
1N/Aph:phl:608:Philippines
1N/Apk:pak:586:Pakistan
1N/Apl:pol:616:Poland
1N/Apm:spm:666:Saint Pierre and Miquelon
1N/Apn:pcn:612:Pitcairn:Pitcairn Island
1N/Apr:pri:630:Puerto Rico
1N/Aps:pse:275:Palestinian Territory, Occupied
1N/Apt:prt:620:Portugal
1N/Apw:plw:585:Palau
1N/Apy:pry:600:Paraguay
1N/Aqa:qat:634:Qatar
1N/Are:reu:638:Reunion
1N/Aro:rom:642:Romania
1N/Aru:rus:643:Russian Federation:Russia
1N/Arw:rwa:646:Rwanda
1N/Asa:sau:682:Saudi Arabia
1N/Asb:slb:090:Solomon Islands
1N/Asc:syc:690:Seychelles
1N/Asd:sdn:736:Sudan
1N/Ase:swe:752:Sweden
1N/Asg:sgp:702:Singapore
1N/Ash:shn:654:Saint Helena
1N/Asi:svn:705:Slovenia
1N/Asj:sjm:744:Svalbard and Jan Mayen:Jan Mayen:Svalbard
1N/Ask:svk:703:Slovakia
1N/Asl:sle:694:Sierra Leone
1N/Asm:smr:674:San Marino
1N/Asn:sen:686:Senegal
1N/Aso:som:706:Somalia
1N/Asr:sur:740:Suriname
1N/Ast:stp:678:Sao Tome and Principe
1N/Asv:slv:222:El Salvador
1N/Asy:syr:760:Syrian Arab Republic:Syria
1N/Asz:swz:748:Swaziland
1N/Atc:tca:796:Turks and Caicos Islands
1N/Atd:tcd:148:Chad
1N/Atf:atf:260:French Southern Territories
1N/Atg:tgo:768:Togo
1N/Ath:tha:764:Thailand
1N/Atj:tjk:762:Tajikistan
1N/Atk:tkl:772:Tokelau
1N/Atm:tkm:795:Turkmenistan
1N/Atn:tun:788:Tunisia
1N/Ato:ton:776:Tonga
1N/Atl:tls:626:East Timor
1N/Atr:tur:792:Turkey
1N/Att:tto:780:Trinidad and Tobago
1N/Atv:tuv:798:Tuvalu
1N/Atw:twn:158:Taiwan, Province of China:Taiwan
1N/Atz:tza:834:Tanzania, United Republic of:Tanzania
1N/Aua:ukr:804:Ukraine
1N/Aug:uga:800:Uganda
1N/Aum:umi:581:United States Minor Outlying Islands
1N/Aus:usa:840:United States:USA:United States of America
1N/Auy:ury:858:Uruguay
1N/Auz:uzb:860:Uzbekistan
1N/Ava:vat:336:Holy See (Vatican City State):Holy See (Vatican City)
1N/Avc:vct:670:Saint Vincent and the Grenadines
1N/Ave:ven:862:Venezuela
1N/Avg:vgb:092:Virgin Islands, British:British Virgin Islands
1N/Avi:vir:850:Virgin Islands, U.S.
1N/Avn:vnm:704:Vietnam
1N/Avu:vut:548:Vanuatu
1N/Awf:wlf:876:Wallis and Futuna
1N/Aws:wsm:882:Samoa
1N/Aye:yem:887:Yemen
1N/Ayt:myt:175:Mayotte
1N/Ayu:yug:891:Yugoslavia
1N/Aza:zaf:710:South Africa
1N/Azm:zmb:894:Zambia
1N/Azr:zar:180:Zaire:Congo, The Democratic Republic of the:Congo, Democratic Republic of the
1N/Azw:zwe:716:Zimbabwe