Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nationality dict #17

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions django_country_kit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
266 changes: 266 additions & 0 deletions django_country_kit/nationalities.py
Original file line number Diff line number Diff line change
@@ -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",
}
Loading