diff --git a/django_country_kit/base.py b/django_country_kit/base.py index 9bfb71a..6ed26de 100644 --- a/django_country_kit/base.py +++ b/django_country_kit/base.py @@ -18,6 +18,7 @@ - Country (class): A class representing a country with properties for accessing its name and alpha3 code. """ from .data import get_countries +from .nationalities import NATIONALITIES class Country: @@ -81,3 +82,15 @@ def get_code_from_name(self, name: str) -> str: if data['name'] == name: return code return '' + + def get_code_from_nationality(self, nationality: str) -> str: + """ + Get the country code from the nationality. + + Args: + nationality (str): The nationality of the country. + + Returns: + str: The country code. + """ + return NATIONALITIES.get(nationality, None) diff --git a/django_country_kit/nationalities.py b/django_country_kit/nationalities.py new file mode 100644 index 0000000..9601d28 --- /dev/null +++ b/django_country_kit/nationalities.py @@ -0,0 +1,266 @@ +""" +This module defines a dictionary of nationalities and their corresponding +alpha-2 country codes. + +The `NATIONALITIES` dictionary maps each nationality to its respective +alpha-2 country code, where the keys are nationality names (in English) +and the values are ISO 3166-1 alpha-2 codes. + +Example usage: + - "Afghan" -> "AF" + - "Åland Island" -> "AX" + +The dictionary can be used for looking up the alpha-2 code based on a +given nationality name. + +Usage: + from nationality_module import NATIONALITIES + print(NATIONALITIES["Afghan"]) # Output: 'AF' +""" +NATIONALITIES = { + "Afghan": "AF", + "Åland Island": "AX", + "Albanian": "AL", + "Algerian": "DZ", + "American Samoan": "AS", + "Andorran": "AD", + "Angolan": "AO", + "Anguillan": "AI", + "Antarctic": "AQ", + "Antiguan or Barbudan": "AG", + "Argentine": "AR", + "Armenian": "AM", + "Aruban": "AW", + "Australian": "AU", + "Austrian": "AT", + "Azerbaijani": "AZ", + "Bahamian": "BS", + "Bahraini": "BH", + "Bangladeshi": "BD", + "Barbadian": "BB", + "Belarusian": "BY", + "Belgian": "BE", + "Belizean": "BZ", + "Beninese": "BJ", + "Bermudian": "BM", + "Bhutanese": "BT", + "Bolivian": "BO", + "Bonaire": "BQ", + "Bosnian": "BA", + "Botswanan": "BW", + "Bouvet Island": "BV", + "Brazilian": "BR", + "BIOT": "IO", + "Bruneian": "BN", + "Bulgarian": "BG", + "Burkinabé": "BF", + "Burundian": "BI", + "Cabo Verdean": "CV", + "Cambodian": "KH", + "Cameroonian": "CM", + "Canadian": "CA", + "Caymanian": "KY", + "Central African": "CF", + "Chadian": "TD", + "Chilean": "CL", + "Chinese": "CN", + "Christmas Island": "CX", + "Cocos Island": "CC", + "Colombian": "CO", + "Comorian": "KM", + "Congolese": "CD", + "Cook Island": "CK", + "Costa Rican": "CR", + "Ivorian": "CI", + "Croatian": "HR", + "Cuban": "CU", + "Curaçaoan": "CW", + "Cypriot": "CY", + "Czech": "CZ", + "Danish": "DK", + "Djiboutian": "DJ", + "Dominican": "DO", + "Ecuadorian": "EC", + "Egyptian": "EG", + "Salvadoran": "SV", + "Equatorial Guinean": "GQ", + "Eritrean": "ER", + "Estonian": "EE", + "Ethiopian": "ET", + "Falkland Island": "FK", + "Faroese": "FO", + "Fijian": "FJ", + "Finnish": "FI", + "French": "FR", + "French Guianese": "GF", + "French Polynesian": "PF", + "French Southern Territories": "TF", + "Gabonese": "GA", + "Gambian": "GM", + "Georgian": "GE", + "German": "DE", + "Ghanaian": "GH", + "Gibraltar": "GI", + "Greek": "GR", + "Greenlandic": "GL", + "Grenadian": "GD", + "Guadeloupe": "GP", + "Guamanian": "GU", + "Guatemalan": "GT", + "Channel Island": "JE", + "Guinean": "GN", + "Bissau-Guinean": "GW", + "Guyanese": "GY", + "Haitian": "HT", + "Heard Island or McDonald Islands": "HM", + "Vatican": "VA", + "Honduran": "HN", + "Hong Kong": "HK", + "Hungarian": "HU", + "Icelandic": "IS", + "Indian": "IN", + "Indonesian": "ID", + "Iranian": "IR", + "Iraqi": "IQ", + "Irish": "IE", + "Manx": "IM", + "Israeli": "IL", + "Italian": "IT", + "Jamaican": "JM", + "Japanese": "JP", + "Jordanian": "JO", + "Kazakhstani, Kazakh": "KZ", + "Kenyan": "KE", + "I-Kiribati": "KI", + "North Korean": "KP", + "South Korean": "KR", + "Kuwaiti": "KW", + "Kyrgyz": "KG", + "Lao": "LA", + "Latvian": "LV", + "Lebanese": "LB", + "Basotho": "LS", + "Liberian": "LR", + "Libyan": "LY", + "Liechtenstein": "LI", + "Lithuanian": "LT", + "Luxembourgish": "LU", + "Macanese": "MO", + "Macedonian": "MK", + "Malagasy": "MG", + "Malawian": "MW", + "Malaysian": "MY", + "Maldivian": "MV", + "Malinese": "ML", + "Maltese": "MT", + "Marshallese": "MH", + "Martiniquais": "MQ", + "Mauritanian": "MR", + "Mauritian": "MU", + "Mahoran": "YT", + "Mexican": "MX", + "Micronesian": "FM", + "Moldovan": "MD", + "Monacan": "MC", + "Mongolian": "MN", + "Montenegrin": "ME", + "Montserratian": "MS", + "Moroccan": "MA", + "Mozambican": "MZ", + "Burmese": "MM", + "Namibian": "NA", + "Nauruan": "NR", + "Nepalese": "NP", + "Dutch": "NL", + "New Caledonian": "NC", + "New Zealand": "NZ", + "Nicaraguan": "NI", + "Nigerien": "NE", + "Nigerian": "NG", + "Niuean": "NU", + "Norfolk Island": "NF", + "Northern Marianan": "MP", + "Norwegian": "NO", + "Omani": "OM", + "Pakistani": "PK", + "Palauan": "PW", + "Palestinian": "PS", + "Panamanian": "PA", + "Papua New Guinean": "PG", + "Paraguayan": "PY", + "Peruvian": "PE", + "Philippine": "PH", + "Pitcairn Island": "PN", + "Polish": "PL", + "Portuguese": "PT", + "Puerto Rican": "PR", + "Qatari": "QA", + "Réunionese": "RE", + "Romanian": "RO", + "Russian": "RU", + "Rwandan": "RW", + "Barthélemois": "BL", + "Saint Helenian": "SH", + "Kittitian or Nevisian": "KN", + "Saint Lucian": "LC", + "Saint-Martinoise": "MF", + "Saint-Pierrais or Miquelonnais": "PM", + "Vincentian": "VC", + "Samoan": "WS", + "Sammarinese": "SM", + "São Toméan": "ST", + "Saudi": "SA", + "Senegalese": "SN", + "Serbian": "RS", + "Seychellois": "SC", + "Sierra Leonean": "SL", + "Singaporean": "SG", + "Sint Maarten": "SX", + "Slovak": "SK", + "Slovenian": "SI", + "Solomon Island": "SB", + "Somalian": "SO", + "South African": "ZA", + "South Georgia or South Sandwich Islands": "GS", + "South Sudanese": "SS", + "Spanish": "ES", + "Sri Lankan": "LK", + "Sudanese": "SD", + "Surinamese": "SR", + "Svalbard": "SJ", + "Swazi": "SZ", + "Swedish": "SE", + "Swiss": "CH", + "Syrian": "SY", + "Taiwanese": "TW", + "Tajikistani": "TJ", + "Tanzanian": "TZ", + "Thai": "TH", + "Timorese": "TL", + "Togolese": "TG", + "Tokelauan": "TK", + "Tongan": "TO", + "Trinidadian or Tobagonian": "TT", + "Tunisian": "TN", + "Turkish": "TR", + "Turkmen": "TM", + "Turks and Caicos Island": "TC", + "Tuvaluan": "TV", + "Ugandan": "UG", + "Ukrainian": "UA", + "Emirati": "AE", + "British": "GB", + "American": "US", + "Uruguayan": "UY", + "Uzbek": "UZ", + "Vanuatuan": "VU", + "Venezuelan": "VE", + "Vietnamese": "VN", + "British Virgin Island": "VG", + "U.S. Virgin Island": "VI", + "Wallisian or Futunan": "WF", + "Sahrawi": "EH", + "Yemeni": "YE", + "Zambian": "ZM", + "Zimbabwean": "ZW", +}