本文整理汇总了PHP中sfCultureInfo::getCountries方法的典型用法代码示例。如果您正苦于以下问题:PHP sfCultureInfo::getCountries方法的具体用法?PHP sfCultureInfo::getCountries怎么用?PHP sfCultureInfo::getCountries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfCultureInfo
的用法示例。
在下文中一共展示了sfCultureInfo::getCountries方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_country
function format_country($country_iso, $culture = null)
{
$c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
$countries = $c->getCountries();
if (!isset($countries[$country_iso])) {
$c = new sfCultureInfo(sfConfig::get('sf_default_culture'));
$countries = $c->getCountries();
}
return isset($countries[$country_iso]) ? $countries[$country_iso] : $country_iso;
}
示例2: setCountriesFromCultureInfo
/**
* Set the country list via the sfCultureInfo system.
* @return void
*/
protected function setCountriesFromCultureInfo()
{
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$countries = $c->getCountries();
foreach ($countries as $key => $value) {
if (is_int($key)) {
unset($countries[$key]);
}
}
unset($countries['ZZ']);
$countries = array('' => '--') + $countries;
$this->setCountries($countries);
}
示例3: configure
/**
* Configures the current validator.
*
* Available options:
*
* * culture: The culture to use for internationalized strings (required)
* * countries: An array of country codes to use (ISO 3166)
*
* @param array $options An array of options
* @param array $messages An array of error messages
*
* @see sfValidatorChoice
*/
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
$this->addRequiredOption('culture');
$this->addOption('countries');
// populate choices with all countries
$culture = isset($options['culture']) ? $options['culture'] : 'en';
$cultureInfo = new sfCultureInfo($culture);
$countries = array_keys($cultureInfo->getCountries());
// restrict countries to a sub-set
if (isset($options['countries'])) {
if ($problems = array_diff($options['countries'], $countries)) {
throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
}
$countries = $options['countries'];
}
sort($countries);
$this->setOption('choices', $countries);
}
示例4: format_country
function format_country($country_iso, $culture = null)
{
$c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
$countries = $c->getCountries();
return isset($countries[$country_iso]) ? $countries[$country_iso] : '';
}
示例5: select_country_tag
/**
* Returns a <select> tag populated with all the countries in the world.
*
* The select_country_tag builds off the traditional select_tag function, and is conveniently populated with
* all the countries in the world (sorted alphabetically). Each option in the list has a two-character country
* code for its value and the country's name as its display title. The country data is retrieved via the sfCultureInfo
* class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
* Here's an example of an <option> tag generated by the select_country_tag:
*
* <samp>
* <option value="US">United States</option>
* </samp>
*
* <b>Examples:</b>
* <code>
* echo select_country_tag('country', 'FR');
* </code>
*
* @param string field name
* @param string selected field value (two-character country code)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the countries in the world.
* @see select_tag, options_for_select, sfCultureInfo
*/
function select_country_tag($name, $selected = null, $options = array())
{
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$countries = $c->getCountries();
if ($country_option = _get_option($options, 'countries')) {
foreach ($countries as $key => $value) {
if (!in_array($key, $country_option)) {
unset($countries[$key]);
}
}
}
asort($countries);
$option_tags = options_for_select($countries, $selected, $options);
return select_tag($name, $option_tags, $options);
}
示例6: getCountry
public static function getCountry($iso, $culture)
{
$c = new sfCultureInfo($culture);
$countries = $c->getCountries();
return array_key_exists($iso, $countries) ? $countries[$iso] : '';
}
示例7:
$languages_en = $c_en->getLanguages();
$languages_fr = $c_fr->getLanguages();
$t->is($languages_en['fr'], 'French', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_fr['fr'], 'français', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_en, $c_en->Languages, '->getLanguages() is equivalent to ->Languages');
// ->getCurrencies()
$t->diag('->getCurrencies()');
$currencies_en = $c_en->getCurrencies();
$currencies_fr = $c_fr->getCurrencies();
$t->is($currencies_en['EUR'][1], 'Euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_fr['EUR'][1], 'euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_en, $c_en->Currencies, '->getCurrencies() is equivalent to ->Currencies');
// ->getCountries()
$t->diag('->getCountries()');
$countries_en = $c_en->getCountries();
$countries_fr = $c_fr->getCountries();
$t->is($countries_en['ES'], 'Spain', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_fr['ES'], 'Espagne', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_en, $c_en->Countries, '->getCountries() is equivalent to ->Countries');
// ->getScripts()
$t->diag('->getScripts()');
$scripts_en = $c_en->getScripts();
$scripts_fr = $c_fr->getScripts();
$t->is($scripts_en['Arab'], 'Arabic', '->getScripts() returns a list of scripts in the language of the localized version');
$t->is($scripts_fr['Arab'], 'arabe', '->getScripts() returns a list of scripts in the language of the localized version');
$t->is($scripts_en, $c_en->Scripts, '->getScripts() is equivalent to ->Scripts');
// ->getTimeZones()
$t->diag('->getTimeZones()');
$time_zones_en = $c_en->getTimeZones();
$time_zones_fr = $c_fr->getTimeZones();
$t->is($time_zones_en[1][0], 'America/Los_Angeles', '->getTimeZones() returns a list of time zones in the language of the localized version');
示例8: getCountry
/**
* Gets a country name.
*
* @param string $iso The ISO code
* @param string $culture The culture for the translation
*
* @return string The country name
*/
public function getCountry($iso, $culture = null)
{
$c = new sfCultureInfo(is_null($culture) ? $this->culture : $culture);
$countries = $c->getCountries();
return array_key_exists($iso, $countries) ? $countries[$iso] : '';
}