Something went wrong. Try again.
Easy Address Field is the easiest way to add an address to your entries.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041<?php
namespace studioespresso\easyaddressfield\services;
use Craft;use craft\base\Component;use Giggsey\Locale\Locale;use League\ISO3166\ISO3166;
class CountriesService extends Component{ /** * @return array */ public function getCountriesAsArray() { $data = new ISO3166(); $data = $data->all(); $countries = array(); foreach ($data as $country) { $countries[$country['alpha2']] = Locale::getDisplayRegion('-' . $country['alpha2'], Craft::$app->getLocale()) != '' ? Locale::getDisplayRegion('-' . $country['alpha2'], Craft::$app->getLocale()) : $country['name']; }; asort($countries); return $countries; }
public function getCountryNameByAlpha2($code, $locale) { $data = new ISO3166(); $country = $data->alpha2($code);
try { return Locale::getDisplayRegion('-' . $country['alpha2'], $locale); } catch (\Exception $e) { return $country['name']; } }}