/** * Localize country name * * @param string $code * @return string */ public function getDisplayCountry($code) { $code = strtoupper($code); $countries = Locale::getDisplayCountries($this->request->getLocale()); if (isset($countries[$code])) { return $countries[$code]; } }
/** * @param $code * @param null $locale * * @return string */ public function country($code, $locale = null) { $countries = Locale::getDisplayCountries($locale ?: $this->localeDetector->getLocale()); if (array_key_exists($code, $countries)) { return $this->fixCharset($countries[$code]); } return ''; }
public function testGetDisplayCountriesReturnsFullListForSubLocale() { $this->skipIfIntlExtensionIsNotLoaded(); $countriesDe = Locale::getDisplayCountries('de'); $countriesDeCh = Locale::getDisplayCountries('de_CH'); $this->assertEquals(count($countriesDe), count($countriesDeCh)); $this->assertEquals($countriesDe['BD'], 'Bangladesch'); $this->assertEquals($countriesDeCh['BD'], 'Bangladesh'); }
/** * @Given /^I created country "([^""]*)"$/ * @Given /^there is country "([^""]*)"$/ */ public function thereIsCountry($name, $provinces = null, $flush = true) { /* @var $country CountryInterface */ if (null === ($country = $this->getRepository('country')->findOneBy(array('name' => $name)))) { $country = $this->getRepository('country')->createNew(); $country->setName(trim($name)); $country->setIsoName(array_search($name, Locale::getDisplayCountries(Locale::getDefault()))); if (null !== $provinces) { $provinces = $provinces instanceof TableNode ? $provinces->getHash() : $provinces; foreach ($provinces as $provinceName) { $country->addProvince($this->thereisProvince($provinceName)); } } $manager = $this->getEntityManager(); $manager->persist($country); if ($flush) { $manager->flush(); } } return $country; }
public function addCustomProperty(TransformEvent $event) { $object = $event->getObject(); $document = $event->getDocument(); $document->addGeoPoint('location', $object->getLat(), $object->getLng()); if (!$object->getProvince()) { $locale = 'it'; $countries = Locale::getDisplayCountries($locale); $country = $countries[$object->getCountry()]; $address = $object->getAddress() . ' ' . $object->getTown() . ' ' . $country; try { $result = $this->geocode->using('google_maps')->reverse($object->getLat(), $object->getLng()); $document->set('town', $result->getCity()); $document->set('zipcode', $result->getZipcode()); $document->set('province', $result->getCountyCode()); $document->set('country', $result->getCountryCode()); $document->set('address', $result->getStreetName() . ' ' . $result->getStreetNumber()); $document->set('region', $result->getRegion()); } catch (\Exception $e) { print $object->getId() . '::' . $e->getMessage() . "\n"; } } }
public function testGetDisplayCountries() { $countries = Locale::getDisplayCountries('en'); $this->assertEquals('Brazil', $countries['BR']); }
/** * {@inheritdoc} */ public function getDefaultOptions(array $options) { return array('choices' => Locale::getDisplayCountries(\Locale::getDefault())); }
/** * Translate a country indicator to its locale full name * @param string $country The contry indicator * @param string $default The default value is the country does not exist (optionnal) * @return string The localized string */ public static function countryFilter($country, $default = '') { $countries = Locale::getDisplayCountries(\Locale::getDefault()); return array_key_exists($country, $countries) ? $countries[$country] : $default; }
protected function configure() { $this->addOption('choices', Locale::getDisplayCountries(\Locale::getDefault())); parent::configure(); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('choices' => Locale::getDisplayCountries(\Locale::getDefault()))); }
public function testGetDisplayCountriesForSwitzerland() { IntlTestHelper::requireFullIntl($this); $countries = Locale::getDisplayCountries('de_CH'); $this->assertEquals('Schweiz', $countries['CH']); }
/** * @param $key * @return mixed */ public function country($key) { $countries = Locale::getDisplayCountries($this->app['locale']); return $countries[$key]; }
/** * Translate a country indicator to its locale full name * Uses default system locale by default. Pass another locale string to force a different translation * * @param string $country The contry indicator * @param string $default The default value is the country does not exist (optionnal) * @param mixed $locale * * @return string The localized string * @access public * @static * * @author Etienne de Longeaux <*****@*****.**> */ public function countryFilter($country, $default = '', $locale = null) { $locale = $locale == null ? \Locale::getDefault() : $locale; $countries = Locale::getDisplayCountries($locale); return array_key_exists($country, $countries) ? $countries[$country] : $default; }
/** * {@inheritdoc} */ public function getCountries($language) { return $this->locale->getDisplayCountries($language); }
/** * Returns the country names for locale * * @return array The country names with their codes as keys */ public function getDisplayCountries() { return SymfonyLocale::getDisplayCountries($this->getLocale()); }
public function countryFilter($countryCode, $locale = "en") { $c = \Symfony\Component\Locale\Locale::getDisplayCountries($locale); return array_key_exists($countryCode, $c) ? $c[$countryCode] : $countryCode; }
public function testGetDisplayCountriesForSwitzerland() { $countries = Locale::getDisplayCountries('de_CH'); $this->assertEquals('Schweiz', $countries['CH']); }
/** * {@inheritdoc} */ public function getDefaultOptions(array $options) { return array('choices' => Locale::getDisplayCountries(\Locale::getDefault()), 'value_strategy' => ChoiceList::COPY_CHOICE, 'index_strategy' => ChoiceList::COPY_CHOICE); }