/** * Returns a list of languages the user has selected in their browser’s settings, canonicalized using * {@link LocaleData::getCanonicalID}. * * Internally, this method checks the Accept-Language header that should have accompanied the request. * If that header was not present, the method will return `false`. * * @return array|false The preferred languages, or `false` if Craft is unable to determine them. */ public function getBrowserLanguages() { if (!isset($this->_browserLanguages)) { $this->_browserLanguages = array(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && preg_match_all('/([\\w\\-_]+)\\s*(?:;\\s*q\\s*=\\s*(\\d*\\.\\d*))?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches, PREG_SET_ORDER)) { $weights = array(); foreach ($matches as $match) { $this->_browserLanguages[] = LocaleData::getCanonicalID($match[1]); $weights[] = !empty($match[2]) ? floatval($match[2]) : 1; } // Sort the languages by their weight array_multisort($weights, SORT_NUMERIC, SORT_DESC, $this->_browserLanguages); } } if ($this->_browserLanguages) { return $this->_browserLanguages; } else { return false; } }
/** * Returns the localization data for a given locale. * * @param string $localeId * * @return LocaleData|null */ public function getLocaleData($localeId = null) { if (!$localeId) { $localeId = craft()->language; } if (!isset($this->_localeData) || !array_key_exists($localeId, $this->_localeData)) { if (LocaleData::exists($localeId)) { $this->_localeData[$localeId] = LocaleData::getInstance($localeId); } else { $this->_localeData[$localeId] = null; } } return $this->_localeData[$localeId]; }
<?php $checkbox = $form->checkBox($model, 'enable_appeals') . $model->getAttributeLabel('enable_appeals'); ?> <?php echo CHtml::label($checkbox, 'SettingsForm_enable_appeals', array('class' => 'checkbox')); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'timezone', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'timezone', LocaleData::getTimezones(), array('class' => 'span6')); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'date_format', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->textField($model, 'date_format', array('size' => 60, 'maxlength' => 64, 'placeholder' => 'm-d-y H:i')); ?> <div class="help-inline"><?php echo CHtml::link(Yii::t('sourcebans', 'See') . ': PHP date()', 'http://www.php.net/date', array('target' => '_blank')); ?>
echo $form->label($model, 'theme', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'theme', SourceBans::app()->themes, array('empty' => '- ' . Yii::t('sourcebans', 'Default setting') . ' -')); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'timezone', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'timezone', LocaleData::getTimezones(), array('class' => 'span6', 'empty' => '- ' . Yii::t('sourcebans', 'Default setting') . ' -')); ?> </div> </div> <div class="control-group buttons"> <div class="controls"> <?php echo CHtml::hiddenField('scenario', $model->scenario); ?> <?php echo CHtml::submitButton(Yii::t('sourcebans', 'Save'), array('class' => 'btn')); ?> </div> </div>
/** * @test */ public function it_provides_time_data_for_invalid_locale() { $data = LocaleData::getInstance()->getTimeData('invalid'); $this->assertData($data, 'LC_TIME'); }
/** * Returns the user preferred languages sorted by preference. * The returned language IDs will be canonicalized using {@link LocaleData::getCanonicalID}. * This method returns false if the user does not have language preferences. * * @return array the user preferred languages. */ public function getBrowserLanguages() { if ($this->_browserLanguages === null) { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n = preg_match_all('/([\\w\\-_]+)\\s*(;\\s*q\\s*=\\s*(\\d*\\.\\d*))?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) > 0) { $languages = array(); for ($i = 0; $i < $n; ++$i) { $languages[$matches[1][$i]] = empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]); } // Sort by it's weight. arsort($languages); foreach ($languages as $language => $pref) { $this->_browserLanguages[] = LocaleData::getCanonicalID($language); } } if ($this->_browserLanguages === null) { return false; } } return $this->_browserLanguages; }