当前位置: 首页>>代码示例>>PHP>>正文


PHP sfCultureInfo类代码示例

本文整理汇总了PHP中sfCultureInfo的典型用法代码示例。如果您正苦于以下问题:PHP sfCultureInfo类的具体用法?PHP sfCultureInfo怎么用?PHP sfCultureInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了sfCultureInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: format_language

function format_language($language_iso, $culture = null)
{
    $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
    $languages = $c->getLanguages();
    if (!isset($languages[$language_iso])) {
        $c = new sfCultureInfo(sfConfig::get('sf_default_culture'));
        $languages = $c->getLanguages();
    }
    return isset($languages[$language_iso]) ? $languages[$language_iso] : $language_iso;
}
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:10,代码来源:I18NHelper.php

示例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);
 }
开发者ID:pierswarmers,项目名称:rtCorePlugin,代码行数:17,代码来源:rtWidgetFormSelectCountry.class.php

示例3: setup

 public function setup()
 {
     parent::setup();
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
     $this->setWidget('culture', new sfWidgetFormChoice(array('choices' => $languages)));
 }
开发者ID:rbolliger,项目名称:apostrophePollPlugin,代码行数:7,代码来源:PluginaPollAnswerForm.class.php

示例4: setup

 public function setup()
 {
     parent::setup();
     unset($this['created_at'], $this['updated_at']);
     // checking that some polls are available
     if (false === aPollToolkit::getAvailablePolls(false)) {
         throw new sfException('Cannot find any poll item in apoll_settings_available_polls. Please, define some in app.yml');
     }
     $available_polls = aPollToolkit::getAvailablePolls();
     $choices = array();
     $choices_keys = array();
     foreach ($available_polls as $key => $poll) {
         $choices[$key] = isset($poll['name']) ? $poll['name'] : $key;
         $choices_keys[] = $key;
     }
     $this->widgetSchema['type'] = new sfWidgetFormChoice(array('choices' => $choices));
     $this->validatorSchema['type'] = new sfValidatorAnd(array(new sfValidatorChoice(array('choices' => $choices_keys, 'required' => true)), new aPollValidatorPollItem(array('poll_items' => aPollToolkit::getAvailablePolls()))), array('halt_on_error' => true));
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $date_options = array('image' => '/apostrophePlugin/images/a-icon-datepicker.png', 'culture' => $culture, 'config' => '{changeMonth: true,changeYear: true}');
     $time_attributes = array('twenty-four-hour' => true, 'minutes-increment' => 30);
     $this->setWidget('published_from', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
     $this->setWidget('published_to', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
     $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateEndDate'))));
     $this->setWidget('submissions_allow_multiple', new aWidgetFormChoice(array('choices' => array(true => 'Yes', false => 'No'))));
     $this->setWidget('submissions_delay', new sfWidgetFormTime(array('hours' => self::generateTwoCharsRange(0, 120)), $time_attributes));
     // setting translation catalogue
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
     // embedding i18n fields
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
     $this->embedI18n(array_keys($languages));
     foreach ($languages as $key => $value) {
         $this->widgetSchema->setLabel($key, ucfirst($value));
     }
 }
开发者ID:rbolliger,项目名称:apostrophePollPlugin,代码行数:35,代码来源:PluginaPollPollForm.class.php

示例5: object_multiselect_language_tag

/**
 * Returns a <selectize> tag populated with all the languages in the world (or almost).
 *
 * The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
 * all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
 * language/culture code for its value and the language'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="en">English</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_language_tag('language', 'de');
 * </code>
 *
 * @param  string $name     field name
 * @param  string $selected selected field values (two or three-character language/culture code)
 * @param  array  $options  additional HTML compliant <select> tag parameters
 *
 * @return string <selectize> tag populated with all the languages in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function object_multiselect_language_tag($name, $selected = null, $options = array())
{
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $languages = $c->getLanguages();
    if ($language_option = _get_option($options, 'languages')) {
        foreach ($languages as $key => $value) {
            if (!in_array($key, $language_option)) {
                unset($languages[$key]);
            }
        }
    }
    asort($languages);
    $option_tags = options_for_select($languages, $selected, $options);
    unset($options['include_blank'], $options['include_custom']);
    return select_tag($name, $option_tags, $options);
}
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:41,代码来源:LanguageHelper.php

示例6: render_field

function render_field($field, $resource, array $options = array())
{
    $options += array('name' => $field->getName());
    $div = null;
    $culture = sfContext::getInstance()->user->getCulture();
    if (isset($resource) && $culture != $resource->sourceCulture && 0 < strlen($source = $resource->__get($options['name'], array('sourceCulture' => true)))) {
        // TODO Are there cases where the direction of this <div/>'s containing
        // block isn't the direction of the current culture?
        $dir = null;
        $sourceCultureInfo = sfCultureInfo::getInstance($resource->sourceCulture);
        if (sfCultureInfo::getInstance($culture)->direction != $sourceCultureInfo->direction) {
            $dir = " dir=\"{$sourceCultureInfo->direction}\"";
        }
        $div = <<<div
<div class="default-translation"{$dir}>
  {$source}
</div>

div;
    }
    unset($options['name']);
    return <<<return
<div class="form-item">
  {$field->renderLabel()}
  {$field->renderError()}
  {$div}
  {$field->render($options)}
  {$field->renderHelp()}
</div>

return;
}
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:32,代码来源:QubitHelper.php

示例7: addField

 protected function addField($name)
 {
     switch ($name) {
         case 'username':
             $this->form->setDefault('username', $this->resource->username);
             $this->form->setValidator('username', new sfValidatorString(array('required' => true)));
             $this->form->setWidget('username', new sfWidgetFormInput());
             break;
         case 'email':
             $this->form->setDefault('email', $this->resource->email);
             $this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
             $this->form->setWidget('email', new sfWidgetFormInput());
             break;
         case 'password':
         case 'confirmPassword':
             $this->form->setDefault($name, null);
             // Required field only if a new user is being created
             $this->form->setValidator($name, new sfValidatorString(array('required' => !isset($this->getRoute()->resource))));
             $this->form->setWidget($name, new sfWidgetFormInputPassword());
             break;
         case 'groups':
             $values = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclUserGroup::USER_ID, $this->resource->id);
             foreach (QubitAclUserGroup::get($criteria) as $item) {
                 $values[] = $item->groupId;
             }
             $choices = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclGroup::ID, 99, Criteria::GREATER_THAN);
             foreach (QubitAclGroup::get($criteria) as $item) {
                 $choices[$item->id] = $item->getName(array('cultureFallback' => true));
             }
             $this->form->setDefault('groups', $values);
             $this->form->setValidator('groups', new sfValidatorPass());
             $this->form->setWidget('groups', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'translate':
             $c = sfCultureInfo::getInstance($this->context->user->getCulture());
             $languages = $c->getLanguages();
             $choices = array();
             if (0 < count($langSettings = QubitSetting::getByScope('i18n_languages'))) {
                 foreach ($langSettings as $item) {
                     $choices[$item->name] = $languages[$item->name];
                 }
             }
             // Find existing translate permissions
             $criteria = new Criteria();
             $criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
             $criteria->add(QubitAclPermission::ACTION, 'translate');
             $defaults = null;
             if (null !== ($permission = QubitAclPermission::getOne($criteria))) {
                 $defaults = $permission->getConstants(array('name' => 'languages'));
             }
             $this->form->setDefault('translate', $defaults);
             $this->form->setValidator('translate', new sfValidatorPass());
             $this->form->setWidget('translate', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
     }
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:60,代码来源:editAction.class.php

示例8: getComputedAddress

 public function getComputedAddress($culture = 'en')
 {
     $address = $this->getField(Petition::FIELD_ADDRESS);
     $postcode = $this->getField(Petition::FIELD_POSTCODE);
     $city = $this->getField(Petition::FIELD_CITY);
     try {
         $country = sfCultureInfo::getInstance($culture)->getCountry($this->getField(Petition::FIELD_COUNTRY));
     } catch (Exception $e) {
         $country = $this->getField(Petition::FIELD_COUNTRY);
     }
     $ret = $this->getComputedName();
     if ($address) {
         $ret .= "\n" . $address;
     }
     if ($city) {
         if ($postcode) {
             $ret .= "\n" . $postcode . ' ' . $city;
         } else {
             $ret .= "\n" . $city;
         }
     } else {
         if ($postcode) {
             $ret .= "\n" . $postcode;
         }
     }
     if ($country) {
         $ret .= "\n" . $country;
     }
     return $ret;
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:30,代码来源:PetitionSigningWave.class.php

示例9: configure

 public function configure()
 {
     unset($this['status'], $this['campaign_id'], $this['first_widget_id'], $this['email']);
     $this->widgetSchema->setFormFormatterName('policat');
     $countries_false = array_keys(sfCultureInfo::getInstance()->getCountries());
     $countries = array();
     foreach ($countries_false as $country) {
         if (!is_numeric($country)) {
             $countries[] = $country;
         }
     }
     $countries = array_diff($countries, array('QU', 'ZZ', 'MF'));
     $this->setWidget('country', new sfWidgetFormI18nChoiceCountry(array('countries' => $countries, 'add_empty' => 'Country')));
     $this->setValidator('country', new sfValidatorI18nChoiceCountry(array('countries' => $countries, 'required' => true)));
     //$this->setValidator('email', new ValidatorEmail());
     $this->setWidget('password', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
     $this->setValidator('password', new sfValidatorString(array('min_length' => 20, 'max_length' => 100, 'required' => true)));
     $this->setWidget('password_again', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
     $this->setValidator('password_again', new sfValidatorString());
     $this->getWidgetSchema()->moveField('password_again', sfWidgetFormSchema::AFTER, 'password');
     $this->getValidatorSchema()->setPostValidator(new sfValidatorSchemaCompare('password', '===', 'password_again', array(), array('invalid' => 'passwords do not match')));
     $this->getWidgetSchema()->setHelp('password', 'at least 20 characters');
     foreach (array('firstname', 'lastname', 'function', 'organisation', 'phone', 'address') as $field) {
         $this->getValidator($field)->setOption('required', true);
     }
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:26,代码来源:OwnerForm.class.php

示例10: configure

 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $this->addOption('culture', $culture);
     $this->addOption('languages');
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($options['languages']) ? $options['languages'] : null);
     $cultures = sfCultureInfo::getInstance($culture)->getCultures();
     $countries = sfCultureInfo::getInstance($culture)->getCountries();
     $values = array();
     foreach ($cultures as $key => $culture_info) {
         if (strlen($culture_info) == 5) {
             $culture_small = substr($culture_info, 0, 2);
             $countrie_small = substr($culture_info, 3, 2);
             if (array_key_exists($culture_small, $languages) && array_key_exists($countrie_small, $countries)) {
                 $select_language = preg_replace('/^[' . $culture_small . ']{2}/i', $languages[$culture_small], $culture_info);
                 $select = preg_replace('/[' . $countrie_small . ']{2}$/i', '(' . $countries[$countrie_small] . ')', $select_language);
                 $values[$culture_info] = ucfirst(str_replace('_', ' ', $select));
             }
         }
     }
     if (count($values) == 0) {
         $values[''] = 'No languages found';
     }
     asort($values);
     $this->setOption('choices', $values);
 }
开发者ID:alexhandzhiev,项目名称:sifact,代码行数:27,代码来源:sfExtraWidgetFormSelectCulture.class.php

示例11: _current_language

 function _current_language()
 {
     try {
         return sfContext::getInstance()->getUser()->getCulture();
     } catch (Exception $e) {
         return sfCultureInfo::getInstance()->getName();
     }
 }
开发者ID:rafaelgou,项目名称:brFormExtraPlugin,代码行数:8,代码来源:sfWidgetFormI18nNumber.php

示例12: 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);
 }
开发者ID:ajith24,项目名称:ajithworld,代码行数:32,代码来源:sfValidatorI18nChoiceCountry.class.php

示例13: configure

 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $this->addOption('languages');
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $languages = $cultureInfo->getLanguages();
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], array_keys($languages))) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = array_intersect_key($languages, array_flip($options['languages']));
     }
     asort($languages);
     $this->setOption('choices', $languages);
 }
开发者ID:ajith24,项目名称:ajithworld,代码行数:32,代码来源:sfWidgetFormI18nSelectLanguage.class.php

示例14: getCultureSelect

 protected function getCultureSelect()
 {
     if ($this->i18n->hasManyCultures()) {
         $cultures = array();
         foreach ($this->i18n->getCultures() as $key) {
             $cultures[$key] = sfCultureInfo::getInstance($key)->getLanguage($key);
         }
         return new sfWidgetFormSelect(array('choices' => $cultures));
     }
 }
开发者ID:jdart,项目名称:diem,代码行数:10,代码来源:dmToolBarView.php

示例15: embedI18n

 /**
  * Embed i18n to the given form if it is enabled
  *
  * @param string $name 
  * @param sfForm $form 
  * @return void
  */
 public static function embedI18n($name, sfForm $form)
 {
     if (sfSympalConfig::isI18nEnabled($name)) {
         $context = sfContext::getInstance();
         $culture = $context->getUser()->getEditCulture();
         $form->embedI18n(array(strtolower($culture)));
         $widgetSchema = $form->getWidgetSchema();
         $context->getConfiguration()->loadHelpers(array('Helper'));
         $c = sfCultureInfo::getInstance($culture);
         $languages = $c->getLanguages();
         $language = isset($languages[$culture]) ? $languages[$culture] : '';
         $widgetSchema[$culture]->setLabel($language);
     }
 }
开发者ID:RafalJachimczyk,项目名称:sympal,代码行数:21,代码来源:sfSympalFormToolkit.class.php


注:本文中的sfCultureInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。