本文整理汇总了PHP中sfCultureInfo::validCulture方法的典型用法代码示例。如果您正苦于以下问题:PHP sfCultureInfo::validCulture方法的具体用法?PHP sfCultureInfo::validCulture怎么用?PHP sfCultureInfo::validCulture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfCultureInfo
的用法示例。
在下文中一共展示了sfCultureInfo::validCulture方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getChoices
public function getChoices()
{
// populate choices with all languages
$culture = isset($this->options['culture']) ? $this->options['culture'] : 'en';
$languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($this->options['languages']) ? $this->options['languages'] : null);
foreach ($languages as $iso => $language) {
if (!sfCultureInfo::validCulture($iso)) {
unset($languages[$iso]);
}
}
$addEmpty = isset($this->options['add_empty']) ? $this->options['add_empty'] : false;
if (false !== $addEmpty) {
$languages = array('' => true === $addEmpty ? '' : $addEmpty) + $languages;
}
return $languages;
}
示例2: date
$context->user->culture = 'fr';
$t->is(format_date($now, 'F', 'en'), date('F j, Y g:i:s A', $now).' '.date('T', $now), 'format_date() takes a culture as its third argument');
// format_datetime()
$t->diag('format_datetime()');
$context->user->culture = 'en';
$t->is(format_datetime($now), date('F j, Y g:i:s A', $now).' '.date('T', $now), 'format_datetime() format a numerical date time according to the user culture');
$t->is(format_datetime(date('Y-m-d', $now)), date('F j, Y', $now).' 12:00:00 AM '.date('T', $now), 'format_datetime() format a string date time according to the user culture');
$t->is(format_datetime(date('Y-m-d H:i:s', $now), 'f'), date('F j, Y g:i A', $now), 'formats timestamps correctly');
$t->diag('sfDateFormat');
$df = new sfDateFormat('en_US');
$t->is($df->format('7/14/1789', 'i', 'd'), '1789-07-14', 'pre-epoch date from en_US to iso');
$t->is($df->format('7/14/1789 14:29', 'I', $df->getInputPattern('g')), '1789-07-14 14:29:00', 'pre-epoch date-time from en_US to iso with getInputPattern()');
$df = new sfDateFormat('fr');
$t->is($df->format(date('d/m/y', $now), 'i', 'd'), date('Y-m-d', $now), 'format two digit year from fr to iso');
$cultures = sfCultureInfo::getCultures();
foreach ($cultures as $culture)
{
if (sfCultureInfo::validCulture($culture))
{
$df = new sfDateFormat($culture);
$shortDate = $df->format($now, 'd');
$t->is($df->format($shortDate, 'i', 'd'), date('Y-m-d', $now), sprintf('"%s": conversion "d" to "i"', $culture));
$dateTime = $df->format($now, $df->getInputPattern('g'));
$t->is($df->format($dateTime, 'I', $df->getInputPattern('g')), date('Y-m-d H:i:', $now).'00', sprintf('"%s": Conversion "g" to "I"', $culture));
}
}
示例3:
$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');
$t->is($time_zones_fr[1][0], 'America/Vancouver', '->getTimeZones() returns a list of time zones in the language of the localized version');
$t->is($time_zones_en, $c_en->TimeZones, '->getTimeZones() is equivalent to ->TimeZones');
// ->validCulture()
$t->diag('->validCulture()');
$t->is($c->validCulture('fr'), true, '->validCulture() returns true if the culture is valid');
$t->is($c->validCulture('fr_FR'), true, '->validCulture() returns true if the culture is valid');
foreach (array('xxx', 'pp', 'frFR') as $culture) {
$t->is($c->validCulture($culture), false, '->validCulture() returns false if the culture does not exist');
}
// ::getCultures()
$t->diag('::getCultures()');
$cultures = sfCultureInfo::getCultures();
$t->is(in_array('fr', $cultures), true, '::getCultures() returns an array of all available cultures');
$t->is(in_array('fr_FR', $cultures), true, '::getCultures() returns an array of all available cultures');
$cultures = sfCultureInfo::getCultures(sfCultureInfo::NEUTRAL);
$t->is(in_array('fr', $cultures), true, '::getCultures() returns an array of all available cultures');
$t->is(in_array('fr_FR', $cultures), false, '::getCultures() returns an array of all available cultures');
$cultures = sfCultureInfo::getCultures(sfCultureInfo::SPECIFIC);
$t->is(in_array('fr', $cultures), false, '::getCultures() returns an array of all available cultures');
$t->is(in_array('fr_FR', $cultures), true, '::getCultures() returns an array of all available cultures');