From: Moritz Bunkus Date: Fri, 28 Feb 2020 10:59:27 +0000 (+0100) Subject: ISO 3166: Mapping von Ländernamen auf ISO 3166-1 Alpha 2-Codes X-Git-Tag: release-3.5.6.1~245^2~33 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d5709d396ba161418a3cd2019bcf07a39872f208;p=kivitendo-erp.git ISO 3166: Mapping von Ländernamen auf ISO 3166-1 Alpha 2-Codes --- diff --git a/SL/Helper/ISO3166.pm b/SL/Helper/ISO3166.pm new file mode 100644 index 000000000..9e8b660a7 --- /dev/null +++ b/SL/Helper/ISO3166.pm @@ -0,0 +1,278 @@ +package SL::Helper::ISO3166; + +use strict; +use warnings; +use utf8; + +use Exporter qw(import); +our @EXPORT_OK = qw(map_name_to_alpha_2_code); + +use List::Util qw(first); + +my @alpha_2_mappings = ( + [ 'AD', qr{^(?:AD|Andorra)$}i ], + [ 'AE', qr{^(?:AE|United Arab Emirates)$}i ], + [ 'AF', qr{^(?:AF|Afghanistan)$}i ], + [ 'AG', qr{^(?:AG|Antigua and Barbuda)$}i ], + [ 'AI', qr{^(?:AI|Anguilla)$}i ], + [ 'AL', qr{^(?:AL|Albania)$}i ], + [ 'AM', qr{^(?:AM|Armenia)$}i ], + [ 'AO', qr{^(?:AO|Angola)$}i ], + [ 'AQ', qr{^(?:AQ|Antarctica)$}i ], + [ 'AR', qr{^(?:AR|Argentina)$}i ], + [ 'AS', qr{^(?:AS|American Samoa)$}i ], + [ 'AT', qr{^(?:AT|A|Austria|Österreich)$}i ], + [ 'AU', qr{^(?:AU|Australia)$}i ], + [ 'AW', qr{^(?:AW|Aruba)$}i ], + [ 'AX', qr{^(?:AX|Åland Islands)$}i ], + [ 'AZ', qr{^(?:AZ|Azerbaijan)$}i ], + [ 'BA', qr{^(?:BA|Bosnia and Herzegovina)$}i ], + [ 'BB', qr{^(?:BB|Barbados)$}i ], + [ 'BD', qr{^(?:BD|Bangladesh)$}i ], + [ 'BE', qr{^(?:BE|Belgium)$}i ], + [ 'BF', qr{^(?:BF|Burkina Faso)$}i ], + [ 'BG', qr{^(?:BG|Bulgaria)$}i ], + [ 'BH', qr{^(?:BH|Bahrain)$}i ], + [ 'BI', qr{^(?:BI|Burundi)$}i ], + [ 'BJ', qr{^(?:BJ|Benin)$}i ], + [ 'BL', qr{^(?:BL|Saint Barthélemy)$}i ], + [ 'BM', qr{^(?:BM|Bermuda)$}i ], + [ 'BN', qr{^(?:BN|Brunei Darussalam)$}i ], + [ 'BO', qr{^(?:BO|Bolivia \(Plurinational State of\))$}i ], + [ 'BQ', qr{^(?:BQ|Bonaire, Sint Eustatius and Saba)$}i ], + [ 'BR', qr{^(?:BR|Brazil)$}i ], + [ 'BS', qr{^(?:BS|Bahamas)$}i ], + [ 'BT', qr{^(?:BT|Bhutan)$}i ], + [ 'BV', qr{^(?:BV|Bouvet Island)$}i ], + [ 'BW', qr{^(?:BW|Botswana)$}i ], + [ 'BY', qr{^(?:BY|Belarus)$}i ], + [ 'BZ', qr{^(?:BZ|Belize)$}i ], + [ 'CA', qr{^(?:CA|Canada)$}i ], + [ 'CC', qr{^(?:CC|Cocos \(Keeling\) Islands|Cocos Islands|Keeling Islands)$}i ], + [ 'CD', qr{^(?:CD|Congo, Democratic Republic of the)$}i ], + [ 'CF', qr{^(?:CF|Central African Republic)$}i ], + [ 'CG', qr{^(?:CG|Congo)$}i ], + [ 'CH', qr{^(?:CH|Switzerland|Schweiz)$}i ], + [ 'CI', qr{^(?:CI|Côte d'Ivoire)$}i ], + [ 'CK', qr{^(?:CK|Cook Islands)$}i ], + [ 'CL', qr{^(?:CL|Chile)$}i ], + [ 'CM', qr{^(?:CM|Cameroon)$}i ], + [ 'CN', qr{^(?:CN|China)$}i ], + [ 'CO', qr{^(?:CO|Colombia)$}i ], + [ 'CR', qr{^(?:CR|Costa Rica)$}i ], + [ 'CU', qr{^(?:CU|Cuba)$}i ], + [ 'CV', qr{^(?:CV|Cabo Verde)$}i ], + [ 'CW', qr{^(?:CW|Curaçao)$}i ], + [ 'CX', qr{^(?:CX|Christmas Island)$}i ], + [ 'CY', qr{^(?:CY|Cyprus)$}i ], + [ 'CZ', qr{^(?:CZ|Czechia)$}i ], + [ 'DE', qr{^(?:DE|Germany|D|Deutschland)$}i ], + [ 'DJ', qr{^(?:DJ|Djibouti)$}i ], + [ 'DK', qr{^(?:DK|Denmark)$}i ], + [ 'DM', qr{^(?:DM|Dominica)$}i ], + [ 'DO', qr{^(?:DO|Dominican Republic)$}i ], + [ 'DZ', qr{^(?:DZ|Algeria)$}i ], + [ 'EC', qr{^(?:EC|Ecuador)$}i ], + [ 'EE', qr{^(?:EE|Estonia)$}i ], + [ 'EG', qr{^(?:EG|Egypt)$}i ], + [ 'EH', qr{^(?:EH|Western Sahara)$}i ], + [ 'ER', qr{^(?:ER|Eritrea)$}i ], + [ 'ES', qr{^(?:ES|Spain)$}i ], + [ 'ET', qr{^(?:ET|Ethiopia)$}i ], + [ 'FI', qr{^(?:FI|Finland)$}i ], + [ 'FJ', qr{^(?:FJ|Fiji)$}i ], + [ 'FK', qr{^(?:FK|Falkland Islands \(Malvinas\)|Falkland Islands|Falklands)$}i ], + [ 'FM', qr{^(?:FM|Micronesia \(Federated States of\)|Micronesia)$}i ], + [ 'FO', qr{^(?:FO|Faroe Islands)$}i ], + [ 'FR', qr{^(?:FR|France)$}i ], + [ 'GA', qr{^(?:GA|Gabon)$}i ], + [ 'GB', qr{^(?:GB|United Kingdom of Great Britain and Northern Ireland)$}i ], + [ 'GD', qr{^(?:GD|Grenada)$}i ], + [ 'GE', qr{^(?:GE|Georgia)$}i ], + [ 'GF', qr{^(?:GF|French Guiana)$}i ], + [ 'GG', qr{^(?:GG|Guernsey)$}i ], + [ 'GH', qr{^(?:GH|Ghana)$}i ], + [ 'GI', qr{^(?:GI|Gibraltar)$}i ], + [ 'GL', qr{^(?:GL|Greenland)$}i ], + [ 'GM', qr{^(?:GM|Gambia)$}i ], + [ 'GN', qr{^(?:GN|Guinea)$}i ], + [ 'GP', qr{^(?:GP|Guadeloupe)$}i ], + [ 'GQ', qr{^(?:GQ|Equatorial Guinea)$}i ], + [ 'GR', qr{^(?:GR|Greece)$}i ], + [ 'GS', qr{^(?:GS|South Georgia and the South Sandwich Islands)$}i ], + [ 'GT', qr{^(?:GT|Guatemala)$}i ], + [ 'GU', qr{^(?:GU|Guam)$}i ], + [ 'GW', qr{^(?:GW|Guinea-Bissau)$}i ], + [ 'GY', qr{^(?:GY|Guyana)$}i ], + [ 'HK', qr{^(?:HK|Hong Kong)$}i ], + [ 'HM', qr{^(?:HM|Heard Island and McDonald Islands)$}i ], + [ 'HN', qr{^(?:HN|Honduras)$}i ], + [ 'HR', qr{^(?:HR|Croatia)$}i ], + [ 'HT', qr{^(?:HT|Haiti)$}i ], + [ 'HU', qr{^(?:HU|Hungary)$}i ], + [ 'ID', qr{^(?:ID|Indonesia)$}i ], + [ 'IE', qr{^(?:IE|Ireland)$}i ], + [ 'IL', qr{^(?:IL|Israel)$}i ], + [ 'IM', qr{^(?:IM|Isle of Man)$}i ], + [ 'IN', qr{^(?:IN|India)$}i ], + [ 'IO', qr{^(?:IO|British Indian Ocean Territory)$}i ], + [ 'IQ', qr{^(?:IQ|Iraq)$}i ], + [ 'IR', qr{^(?:IR|Iran \(Islamic Republic of\)|Iran)$}i ], + [ 'IS', qr{^(?:IS|Iceland)$}i ], + [ 'IT', qr{^(?:IT|Italy)$}i ], + [ 'JE', qr{^(?:JE|Jersey)$}i ], + [ 'JM', qr{^(?:JM|Jamaica)$}i ], + [ 'JO', qr{^(?:JO|Jordan)$}i ], + [ 'JP', qr{^(?:JP|Japan)$}i ], + [ 'KE', qr{^(?:KE|Kenya)$}i ], + [ 'KG', qr{^(?:KG|Kyrgyzstan)$}i ], + [ 'KH', qr{^(?:KH|Cambodia)$}i ], + [ 'KI', qr{^(?:KI|Kiribati)$}i ], + [ 'KM', qr{^(?:KM|Comoros)$}i ], + [ 'KN', qr{^(?:KN|Saint Kitts and Nevis)$}i ], + [ 'KP', qr{^(?:KP|Korea \(Democratic People's Republic of\))$}i ], + [ 'KR', qr{^(?:KR|Korea, Republic of|Republic of Korea|Korea)$}i ], + [ 'KW', qr{^(?:KW|Kuwait)$}i ], + [ 'KY', qr{^(?:KY|Cayman Islands)$}i ], + [ 'KZ', qr{^(?:KZ|Kazakhstan)$}i ], + [ 'LA', qr{^(?:LA|Lao People's Democratic Republic)$}i ], + [ 'LB', qr{^(?:LB|Lebanon)$}i ], + [ 'LC', qr{^(?:LC|Saint Lucia)$}i ], + [ 'LI', qr{^(?:LI|Liechtenstein)$}i ], + [ 'LK', qr{^(?:LK|Sri Lanka)$}i ], + [ 'LR', qr{^(?:LR|Liberia)$}i ], + [ 'LS', qr{^(?:LS|Lesotho)$}i ], + [ 'LT', qr{^(?:LT|Lithuania)$}i ], + [ 'LU', qr{^(?:LU|Luxembourg)$}i ], + [ 'LV', qr{^(?:LV|Latvia)$}i ], + [ 'LY', qr{^(?:LY|Libya)$}i ], + [ 'MA', qr{^(?:MA|Morocco)$}i ], + [ 'MC', qr{^(?:MC|Monaco)$}i ], + [ 'MD', qr{^(?:MD|Moldova, Republic of)$}i ], + [ 'ME', qr{^(?:ME|Montenegro)$}i ], + [ 'MF', qr{^(?:MF|Saint Martin \(French part\)|Saint Martin)$}i ], + [ 'MG', qr{^(?:MG|Madagascar)$}i ], + [ 'MH', qr{^(?:MH|Marshall Islands)$}i ], + [ 'MK', qr{^(?:MK|North Macedonia)$}i ], + [ 'ML', qr{^(?:ML|Mali)$}i ], + [ 'MM', qr{^(?:MM|Myanmar)$}i ], + [ 'MN', qr{^(?:MN|Mongolia)$}i ], + [ 'MO', qr{^(?:MO|Macao)$}i ], + [ 'MP', qr{^(?:MP|Northern Mariana Islands)$}i ], + [ 'MQ', qr{^(?:MQ|Martinique)$}i ], + [ 'MR', qr{^(?:MR|Mauritania)$}i ], + [ 'MS', qr{^(?:MS|Montserrat)$}i ], + [ 'MT', qr{^(?:MT|Malta)$}i ], + [ 'MU', qr{^(?:MU|Mauritius)$}i ], + [ 'MV', qr{^(?:MV|Maldives)$}i ], + [ 'MW', qr{^(?:MW|Malawi)$}i ], + [ 'MX', qr{^(?:MX|Mexico)$}i ], + [ 'MY', qr{^(?:MY|Malaysia)$}i ], + [ 'MZ', qr{^(?:MZ|Mozambique)$}i ], + [ 'NA', qr{^(?:NA|Namibia)$}i ], + [ 'NC', qr{^(?:NC|New Caledonia)$}i ], + [ 'NE', qr{^(?:NE|Niger)$}i ], + [ 'NF', qr{^(?:NF|Norfolk Island)$}i ], + [ 'NG', qr{^(?:NG|Nigeria)$}i ], + [ 'NI', qr{^(?:NI|Nicaragua)$}i ], + [ 'NL', qr{^(?:NL|Netherlands)$}i ], + [ 'NO', qr{^(?:NO|Norway)$}i ], + [ 'NP', qr{^(?:NP|Nepal)$}i ], + [ 'NR', qr{^(?:NR|Nauru)$}i ], + [ 'NU', qr{^(?:NU|Niue)$}i ], + [ 'NZ', qr{^(?:NZ|New Zealand)$}i ], + [ 'OM', qr{^(?:OM|Oman)$}i ], + [ 'PA', qr{^(?:PA|Panama)$}i ], + [ 'PE', qr{^(?:PE|Peru)$}i ], + [ 'PF', qr{^(?:PF|French Polynesia)$}i ], + [ 'PG', qr{^(?:PG|Papua New Guinea)$}i ], + [ 'PH', qr{^(?:PH|Philippines)$}i ], + [ 'PK', qr{^(?:PK|Pakistan)$}i ], + [ 'PL', qr{^(?:PL|Poland)$}i ], + [ 'PM', qr{^(?:PM|Saint Pierre and Miquelon)$}i ], + [ 'PN', qr{^(?:PN|Pitcairn)$}i ], + [ 'PR', qr{^(?:PR|Puerto Rico)$}i ], + [ 'PS', qr{^(?:PS|Palestine, State of)$}i ], + [ 'PT', qr{^(?:PT|Portugal)$}i ], + [ 'PW', qr{^(?:PW|Palau)$}i ], + [ 'PY', qr{^(?:PY|Paraguay)$}i ], + [ 'QA', qr{^(?:QA|Qatar)$}i ], + [ 'RE', qr{^(?:RE|Réunion)$}i ], + [ 'RO', qr{^(?:RO|Romania)$}i ], + [ 'RS', qr{^(?:RS|Serbia)$}i ], + [ 'RU', qr{^(?:RU|Russian Federation)$}i ], + [ 'RW', qr{^(?:RW|Rwanda)$}i ], + [ 'SA', qr{^(?:SA|Saudi Arabia)$}i ], + [ 'SB', qr{^(?:SB|Solomon Islands)$}i ], + [ 'SC', qr{^(?:SC|Seychelles)$}i ], + [ 'SD', qr{^(?:SD|Sudan)$}i ], + [ 'SE', qr{^(?:SE|Sweden)$}i ], + [ 'SG', qr{^(?:SG|Singapore)$}i ], + [ 'SH', qr{^(?:SH|Saint Helena, Ascension and Tristan da Cunha)$}i ], + [ 'SI', qr{^(?:SI|Slovenia)$}i ], + [ 'SJ', qr{^(?:SJ|Svalbard and Jan Mayen)$}i ], + [ 'SK', qr{^(?:SK|Slovakia)$}i ], + [ 'SL', qr{^(?:SL|Sierra Leone)$}i ], + [ 'SM', qr{^(?:SM|San Marino)$}i ], + [ 'SN', qr{^(?:SN|Senegal)$}i ], + [ 'SO', qr{^(?:SO|Somalia)$}i ], + [ 'SR', qr{^(?:SR|Suriname)$}i ], + [ 'SS', qr{^(?:SS|South Sudan)$}i ], + [ 'ST', qr{^(?:ST|Sao Tome and Principe)$}i ], + [ 'SV', qr{^(?:SV|El Salvador)$}i ], + [ 'SX', qr{^(?:SX|Sint Maarten \(Dutch part\)|Sint Maarten)$}i ], + [ 'SY', qr{^(?:SY|Syrian Arab Republic)$}i ], + [ 'SZ', qr{^(?:SZ|Eswatini)$}i ], + [ 'TC', qr{^(?:TC|Turks and Caicos Islands)$}i ], + [ 'TD', qr{^(?:TD|Chad)$}i ], + [ 'TF', qr{^(?:TF|French Southern Territories)$}i ], + [ 'TG', qr{^(?:TG|Togo)$}i ], + [ 'TH', qr{^(?:TH|Thailand)$}i ], + [ 'TJ', qr{^(?:TJ|Tajikistan)$}i ], + [ 'TK', qr{^(?:TK|Tokelau)$}i ], + [ 'TL', qr{^(?:TL|Timor-Leste)$}i ], + [ 'TM', qr{^(?:TM|Turkmenistan)$}i ], + [ 'TN', qr{^(?:TN|Tunisia)$}i ], + [ 'TO', qr{^(?:TO|Tonga)$}i ], + [ 'TR', qr{^(?:TR|Turkey)$}i ], + [ 'TT', qr{^(?:TT|Trinidad and Tobago)$}i ], + [ 'TV', qr{^(?:TV|Tuvalu)$}i ], + [ 'TW', qr{^(?:TW|Taiwan, Province of China)$}i ], + [ 'TZ', qr{^(?:TZ|Tanzania, United Republic of)$}i ], + [ 'UA', qr{^(?:UA|Ukraine)$}i ], + [ 'UG', qr{^(?:UG|Uganda)$}i ], + [ 'UM', qr{^(?:UM|United States Minor Outlying Islands)$}i ], + [ 'US', qr{^(?:US|United States of America)$}i ], + [ 'UY', qr{^(?:UY|Uruguay)$}i ], + [ 'UZ', qr{^(?:UZ|Uzbekistan)$}i ], + [ 'VA', qr{^(?:VA|Holy See)$}i ], + [ 'VC', qr{^(?:VC|Saint Vincent and the Grenadines)$}i ], + [ 'VE', qr{^(?:VE|Venezuela \(Bolivian Republic of\)|Venezuela)$}i ], + [ 'VG', qr{^(?:VG|Virgin Islands \(British\))$}i ], + [ 'VI', qr{^(?:VI|Virgin Islands \(U\.?S\.?\))$}i ], + [ 'VN', qr{^(?:VN|Viet Nam)$}i ], + [ 'VU', qr{^(?:VU|Vanuatu)$}i ], + [ 'WF', qr{^(?:WF|Wallis and Futuna)$}i ], + [ 'WS', qr{^(?:WS|Samoa)$}i ], + [ 'YE', qr{^(?:YE|Yemen)$}i ], + [ 'YT', qr{^(?:YT|Mayotte)$}i ], + [ 'ZA', qr{^(?:ZA|South Africa)$}i ], + [ 'ZM', qr{^(?:ZM|Zambia)$}i ], + [ 'ZW', qr{^(?:ZW|Zimbabwe)$}i ], +); + +sub map_name_to_alpha_2_code { + my ($country) = @_; + + return undef if ($country // '') eq ''; + + my $code = first { $country =~ $_->[1] } @alpha_2_mappings; + return $code->[0] if $code; + + no warnings 'once'; + $::lxdebug->message(LXDebug::WARN(), "ISO3166::map_name_to_alpha_2_code: no mapping found for '$country'"); + + return undef; +} + +1;