本文整理汇总了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());
}
示例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;
}
示例3: getLocale
/**
* Returns the set locale
*
* @return string
*/
public function getLocale()
{
if (null === $this->locale) {
$this->locale = \Locale::getDefault();
}
return $this->locale;
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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'));
}
示例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']);
}
示例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);
}));
}
示例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']);
}
示例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;
}
示例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());
}
示例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']);
}
示例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();
}