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


PHP Locale::getDefault方法代码示例

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


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

示例1: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormatOptionValues, true)) {
         if (is_string($format)) {
             $format = self::DEFAULT_FORMAT;
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
     $formatter->setLenient(false);
     $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
     }
     $builder->setAttribute('date_pattern', $formatter->getPattern());
 }
开发者ID:senthilkumar3282,项目名称:LyraAdminBundle,代码行数:26,代码来源:DatePickerType.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param MailLoaderInterface      $loader     The mail loader
  * @param \Twig_Environment        $renderer   The twig environment
  * @param EventDispatcherInterface $dispatcher The event dispatcher
  */
 public function __construct(MailLoaderInterface $loader, \Twig_Environment $renderer, EventDispatcherInterface $dispatcher)
 {
     $this->loader = $loader;
     $this->renderer = $renderer;
     $this->locale = \Locale::getDefault();
     $this->dispatcher = $dispatcher;
 }
开发者ID:sonatra,项目名称:SonatraMailerBundle,代码行数:14,代码来源:MailTemplater.php

示例3: getLocale

 /**
  * Returns the set locale
  *
  * @return string
  */
 public function getLocale()
 {
     if (null === $this->locale) {
         $this->locale = \Locale::getDefault();
     }
     return $this->locale;
 }
开发者ID:leodido,项目名称:moneylaundry,代码行数:12,代码来源:ScientificNotation.php

示例4: testDefaultLocaleFromHttpHeader

 public function testDefaultLocaleFromHttpHeader()
 {
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'sv-se,sv;q=0.8,en-us;q=0.6,en;q=0.4';
     \Locale::setDefault('fi');
     \Library\Application::init('Console', true);
     $this->assertEquals('sv_SE', \Locale::getDefault());
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:7,代码来源:LocalizationTest.php

示例5: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $value = $form->getViewData();
     // set string representation
     if (true === $value) {
         $value = 'true';
     } elseif (false === $value) {
         $value = 'false';
     } elseif (null === $value) {
         $value = 'null';
     } elseif (is_array($value)) {
         $value = implode(', ', $value);
     } elseif ($value instanceof \DateTime) {
         $dateFormat = is_int($options['date_format']) ? $options['date_format'] : DateType::DEFAULT_FORMAT;
         $timeFormat = is_int($options['time_format']) ? $options['time_format'] : DateType::DEFAULT_FORMAT;
         $calendar = \IntlDateFormatter::GREGORIAN;
         $pattern = is_string($options['date_pattern']) ? $options['date_pattern'] : null;
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, 'UTC', $calendar, $pattern);
         $formatter->setLenient(false);
         $value = $formatter->format($value);
     } elseif (is_object($value)) {
         if (method_exists($value, '__toString')) {
             $value = $value->__toString();
         } else {
             $value = get_class($value);
         }
     }
     $view->vars['value'] = (string) $value;
 }
开发者ID:GeneralMediaCH,项目名称:GenemuFormBundle,代码行数:32,代码来源:PlainType.php

示例6: setUp

 protected function setUp()
 {
     $this->locale = \Locale::getDefault();
     parent::setUp();
     $this->cmMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->formType = new LanguageType($this->cmMock);
 }
开发者ID:Maksold,项目名称:platform,代码行数:7,代码来源:LanguageTypeTest.php

示例7: currencySymbolFunction

 public function currencySymbolFunction($locale)
 {
     $locale = $locale == null ? \Locale::getDefault() : $locale;
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $symbol = $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
     return $symbol;
 }
开发者ID:alisyihab,项目名称:sisdik,代码行数:7,代码来源:LanggasExtension.php

示例8: __construct

    public function __construct($key, array $options = array())
    {
        $this->addOption('trim', true);
        $this->addOption('required', true);
        $this->addOption('disabled', false);
        $this->addOption('property_path', (string)$key);
        $this->addOption('value_transformer');
        $this->addOption('normalization_transformer');

        $this->key = (string)$key;

        if ($this->locale === null) {
            $this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en';
        }

        parent::__construct($options);

        if ($this->getOption('value_transformer')) {
            $this->setValueTransformer($this->getOption('value_transformer'));
        }

        if ($this->getOption('normalization_transformer')) {
            $this->setNormalizationTransformer($this->getOption('normalization_transformer'));
        }

        $this->normalizedData = $this->normalize($this->data);
        $this->transformedData = $this->transform($this->normalizedData);
        $this->required = $this->getOption('required');

        $this->setPropertyPath($this->getOption('property_path'));
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:31,代码来源:Field.php

示例9: buildView

 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $dataType = self::DATA_INTEGER;
     if (isset($options['data_type'])) {
         $dataType = $options['data_type'];
     }
     $formatterOptions = array();
     switch ($dataType) {
         case self::PERCENT:
             $formatterOptions['decimals'] = 2;
             $formatterOptions['grouping'] = false;
             $formatterOptions['percent'] = true;
             break;
         case self::DATA_DECIMAL:
             $formatterOptions['decimals'] = 2;
             $formatterOptions['grouping'] = true;
             break;
         case self::DATA_INTEGER:
         default:
             $formatterOptions['decimals'] = 0;
             $formatterOptions['grouping'] = false;
     }
     $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
     $formatterOptions['orderSeparator'] = $formatterOptions['grouping'] ? $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL) : '';
     $formatterOptions['decimalSeparator'] = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $view->vars['formatter_options'] = array_merge($formatterOptions, $options['formatter_options']);
 }
开发者ID:xamin123,项目名称:platform,代码行数:32,代码来源:NumberFilterType.php

示例10: setDefaultOptions

 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $configs = array_merge($this->options, array('lang' => \Locale::getDefault()));
     $resolver->setDefaults(array('configs' => array(), 'validator' => array(), 'error_bubbling' => false))->setAllowedTypes(array('configs' => 'array', 'validator' => 'array'))->setNormalizers(array('configs' => function (Options $options, $value) use($configs) {
         return array_merge($configs, $value);
     }));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:10,代码来源:ReCaptchaType.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['format'], \IntlDateFormatter::NONE, \DateTimeZone::UTC);
     if ($options['widget'] === 'single_text') {
         $builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         if ($options['widget'] === 'choice') {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
             } else {
                 $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']);
             }
             // Only pass a subset of the options to children
             $yearOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['year'], 'required' => $options['required']);
             $monthOptions = array('choice_list' => new MonthChoiceList($formatter, $options['months']), 'empty_value' => $options['empty_value']['month'], 'required' => $options['required']);
             $dayOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['day'], 'required' => $options['required']);
         }
         $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
             }
         }
     }
     $builder->setAttribute('formatter', $formatter)->setAttribute('widget', $options['widget']);
 }
开发者ID:nightchiller,项目名称:symfony,代码行数:36,代码来源:DateType.php

示例12: parseHeader

 /**
  * Parse header
  *
  * @param   null|\Zend\Http\Header\AcceptLanguage   $header
  * @return  array
  */
 public function parseHeader($header)
 {
     $locales = array();
     $controller = $this->getController();
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $availables = $controller->getServiceLocator()->get('Locale')->getAvailableLocales();
     } else {
         $availables = array(IntlLocale::getDefault());
     }
     if ($header instanceof AcceptLanguage) {
         foreach ($header->getPrioritized() as $part) {
             if ($part instanceof LanguageFieldValuePart) {
                 $locale = IntlLocale::parseLocale($part->getLanguage());
                 $key = $locale['language'];
                 if (isset($locale['region'])) {
                     $key .= '_' . $locale['region'];
                 }
                 if ($availables) {
                     $key = IntlLocale::lookup($availables, $key, false, '');
                 }
                 if ($key) {
                     $locales[$key] = max($part->getPriority(), empty($locales[$key]) ? 0 : $locales[$key]);
                 }
             }
         }
     }
     return $locales;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:34,代码来源:Locale.php

示例13: twig_localized_date_filter

function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null)
{
    $date = twig_date_converter($env, $date, $timezone);
    $formatValues = array('none' => IntlDateFormatter::NONE, 'short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL);
    $formatter = IntlDateFormatter::create($locale !== null ? $locale : Locale::getDefault(), $formatValues[$dateFormat], $formatValues[$timeFormat], $date->getTimezone()->getName());
    return $formatter->format($date->getTimestamp());
}
开发者ID:ideafresh,项目名称:Slim-Boilerplate,代码行数:7,代码来源:Intl.php

示例14: createView

 public function createView(ViewFactory $factory, $data, array $options) : ViewInterface
 {
     $dateFormat = $this->resolveFormat($options['date_format']);
     $timeFormat = $this->resolveFormat($options['time_format']);
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, \IntlDateFormatter::GREGORIAN);
     return new DateTimeView($formatter->format($data), $data, $options['tag']);
 }
开发者ID:symfony-cmf,项目名称:content-type,代码行数:7,代码来源:DateTimeType.php

示例15: __construct

 /**
  * @param FormInterface       $form
  * @param Request             $request
  * @param ObjectManager       $manager
  */
 public function __construct(FormInterface $form, Request $request, ObjectManager $manager)
 {
     $this->form = $form;
     $this->request = $request;
     $this->manager = $manager;
     $this->defaultLocale = \Locale::getDefault();
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:12,代码来源:RequestStatusHandler.php


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