Returns the country alpha2 ISO code.

@author Erik Campobadal Fores <soc@erik.cat>
@copyright 2017 erik.cat
@param string $country
@return string
177630
public static function countryAlpha2(string $country) : string
    {
        $alpha2 = static::simpleCountries()->filter(function ($c) use ($country) {
            return $c === $country;
        })->keys()->first();

        return $alpha2 ? $alpha2 : 'Unknown';
    }
577720
public static function calculateDynamicParts($country) {
    $dynamic_parts = [];
    $addressFormatRepository = \Drupal::service('address.address_format_repository');
    $address_format = $addressFormatRepository->get($country);
    $subdivisionRepository = \Drupal::service('address.subdivision_repository');
    $options = $subdivisionRepository->getList([$country]);
    $labels = LabelHelper::getFieldLabels($address_format);

    // Update region options based on country.
    $dynamic_parts['region']['#options'] = $options;
    $dynamic_parts['region']['#required'] = TRUE;
    $dynamic_parts['region']['#access'] = TRUE;

    // Update labels.
    $cityLabel = $labels['locality'];
    $postcodeLabel = $labels['postalCode'];
    $regionLabel = $labels['administrativeArea'];
    $dynamic_parts['region']['#title'] = $regionLabel;
    $dynamic_parts['postcode']['#title'] = $postcodeLabel;
    $dynamic_parts['city']['#title'] = $cityLabel;

    if (empty($cityLabel)) {
      $dynamic_parts['city']['#required'] = FALSE;
      $dynamic_parts['city']['#access'] = FALSE;
    }

    if (empty($postcodeLabel)) {
      $dynamic_parts['postcode']['#required'] = FALSE;
      $dynamic_parts['postcode']['#access'] = FALSE;
    }

    if (empty($regionLabel) || empty($options)) {
      $dynamic_parts['region']['#required'] = FALSE;
      $dynamic_parts['region']['#access'] = FALSE;
    }

    return $dynamic_parts;
  }
1009610
public CountryCodeDataType.Enum getCountryCodeDataType(String countryCode) {
		CountryCodeDataType.Enum countryCodeDataType = null;
		CountryContract country = s2SLocationService.getCountryFromCode(countryCode);
		if (country != null) {
			StringBuilder countryDetail = new StringBuilder();
			countryDetail.append(country.getAlternateCode());
			countryDetail.append(": ");
			countryDetail.append(country.getName().toUpperCase());
			countryCodeDataType = CountryCodeDataType.Enum
					.forString(countryDetail.toString());
		}
		return countryCodeDataType;
	}
1040941
protected function get($id)
    {
        foreach ($this as $country) {
            if (0 === strcasecmp($id, $country[self::KEY_ALPHA2]) ||
                0 === strcasecmp($id, $country[self::KEY_ALPHA3]) ||
                0 === strcasecmp($id, $country[self::KEY_NUMERIC])
            ) {
                return $country;
            }
        }

        throw new \OutOfBoundsException('ISO 3166-1 does not contain: '.$id);
    }
611478
public function getIsoAlpha2FromName($name)
    {
        // First try and fetch from alpha3 code.
        try {
            return $this->iso->alpha3($this->getCodeFromCountry($name))['alpha2'];
        } catch (OutOfBoundsException $e) {
            // Nothing code continues.
        }

        // Couldn't getch alpha3 from code try from country name.
        try {
            return $this->iso->name($name)['alpha2'];
        } catch (OutOfBoundsException $e) {
            $this->logger->warning("Can't get valid alpha2 code for country '$name'");
        }

        return "OT";
    }
600644
public function getStateName($lookFor, $country = null)
    {
        if ($country) {
            if (! isset($this->states[$country])) {
                $this->findCountryStates($country);
            }

            if (isset($this->states[$country][$lookFor])) {
                return $this->states[$country][$lookFor];
            }

            throw new Exceptions\StateNotFoundException;
        }

        foreach ($this->countries as $countryCode => $countryName) {
            $this->findCountryStates($countryCode);

            if (isset($this->states[$countryCode][$lookFor])) {
                return $this->states[$countryCode][$lookFor];
            }
        }
    }
618606
public function country($country)
    {
        $countries = is_array($country) ? $country : func_get_args();

        $this->countries = array_merge($this->countries, $countries);

        return $this;
    }
1291232
public function getCompanyVatInValidator($country)
    {
        if (is_null($this->_oCompanyVatInValidator)) {
            /** @var \OxidEsales\Eshop\Core\CompanyVatInValidator $vatInValidator */
            $vatInValidator = oxNew('oxCompanyVatInValidator', $country);

            /** @var \OxidEsales\Eshop\Core\CompanyVatInCountryChecker $validator */
            $validator = oxNew(\OxidEsales\Eshop\Core\CompanyVatInCountryChecker::class);

            $vatInValidator->addChecker($validator);

            /** @var \OxidEsales\Eshop\Core\OnlineVatIdCheck $onlineValidator */
            if (!\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam("blVatIdCheckDisabled")) {
                $onlineValidator = oxNew(\OxidEsales\Eshop\Core\OnlineVatIdCheck::class);
                $vatInValidator->addChecker($onlineValidator);
            }

            $this->setCompanyVatInValidator($vatInValidator);
        }

        return $this->_oCompanyVatInValidator;
    }
917419
public static function get($country)
    {
        switch (strtoupper($country)) {
        case "DE":
            return KlarnaEncoding::PNO_DE;
        case "DK":
            return KlarnaEncoding::PNO_DK;
        case "FI":
            return KlarnaEncoding::PNO_FI;
        case "NL":
            return KlarnaEncoding::PNO_NL;
        case "NO":
            return KlarnaEncoding::PNO_NO;
        case "SE":
            return KlarnaEncoding::PNO_SE;
        case "AT":
            return KlarnaEncoding::PNO_AT;
        default:
            return -1;
        }
    }
383586
public function getTopology($country)
    {
        return $this->helper->loadFile(
            $this->helper->dataDir('topo/'.strtolower($country).'.topo.json')
        );
    }
948175
public function getStateCode($lookFor, $country = null)
    {
        $lookFor = mb_strtoupper($lookFor);
        $countries = is_null($country) ? array_keys($this->countries) : (array) $country;

        foreach ($countries as $countryCode) {
            $states = array_map('mb_strtoupper', $this->findCountryStates($countryCode));

            if ($code = array_search($lookFor, $states)) {
                return $code;
            }
        }
    }
394012
public function country(string $country): string
    {
        if (!Configure::read('countries')) {
            Configure::load('CkTools.countries');
        }
        $countries = Configure::read('countries');

        return $countries[$country] ?? $country;
    }
167722
public function getCountryCode($country = null)
    {
        if ($country === null) {
            $country = $this->_country;
        }

        $code = KlarnaCountry::getCode($country);
        return (string) $code;
    }
1254929
def countries(instance):
    
    if (instance['type'] == 'location' and 'country' in instance and not
            instance['country'].upper() in enums.COUNTRY_CODES):

        return JSONError("Location `country` should be a valid ISO 3166-1 "
                         "ALPHA-2 Code.",
                         instance['id'], 'marking-definition-type')
855347
public static function checkLanguage($country, $language)
    {
        switch($country) {
        case KlarnaCountry::AT:
        case KlarnaCountry::DE:
            return ($language === KlarnaLanguage::DE);
        case KlarnaCountry::NL:
            return ($language === KlarnaLanguage::NL);
        case KlarnaCountry::FI:
            return ($language === KlarnaLanguage::FI);
        case KlarnaCountry::DK:
            return ($language === KlarnaLanguage::DA);
        case KlarnaCountry::NO:
            return ($language === KlarnaLanguage::NB);
        case KlarnaCountry::SE:
            return ($language === KlarnaLanguage::SV);
        default:
            //Country not yet supported by Klarna.
            return false;
        }
    }
675570
public function getStateProvinceName($code, $country)
    {
        $all = $this->getAll();
        if (isset($all[$country]) && isset($all[$country][$code])) {
            return $all[$country][$code];
        } else {
            return null;
        }
    }
985503
public function getCountry($countryCode)
    {
        // accept lowercase country codes
        $countryCode = strtoupper($countryCode);

        $result = current(array_filter($this->countries, function ($country) use ($countryCode) {
            /** @var VATCountry $country */
            return ($country->getCode() == $countryCode || $country->getCountryCode() == $countryCode);
        }));

        return $result != false ? $result : null;
    }