Go to the source code of this file.
|
| twig_localized_date_filter (Twig_Environment $env, $date, $dateFormat='medium', $timeFormat='medium', $locale=null, $timezone=null, $format=null, $calendar='gregorian') |
|
| twig_localized_number_filter ($number, $style='decimal', $type='default', $locale=null) |
|
| twig_localized_currency_filter ($number, $currency=null, $locale=null) |
|
| twig_get_number_formatter ($locale, $style) |
| Gets a number formatter instance according to given locale and formatter. More...
|
|
◆ twig_get_number_formatter()
twig_get_number_formatter |
( |
|
$locale, |
|
|
|
$style |
|
) |
| |
Gets a number formatter instance according to given locale and formatter.
- Parameters
-
string | $locale | Locale in which the number would be formatted |
int | $style | Style of the formatting |
- Returns
- NumberFormatter A NumberFormatter instance
Definition at line 100 of file Intl.php.
References $style.
Referenced by twig_localized_currency_filter(), and twig_localized_number_filter().
102 static $formatter, $currentStyle;
104 $locale = $locale !== null ? $locale : Locale::getDefault();
106 if ($formatter && $formatter->getLocale() === $locale && $currentStyle ===
$style) {
112 static $styleValues = array(
113 'decimal' => NumberFormatter::DECIMAL,
114 'currency' => NumberFormatter::CURRENCY,
115 'percent' => NumberFormatter::PERCENT,
116 'scientific' => NumberFormatter::SCIENTIFIC,
117 'spellout' => NumberFormatter::SPELLOUT,
118 'ordinal' => NumberFormatter::ORDINAL,
119 'duration' => NumberFormatter::DURATION,
122 if (!isset($styleValues[
$style])) {
123 throw new Twig_Error_Syntax(sprintf(
'The style "%s" does not exist. Known styles are: "%s"', $style, implode(
'", "', array_keys($styleValues))));
128 $formatter = NumberFormatter::create($locale, $styleValues[$style]);
Exception thrown when a syntax error occurs during lexing or parsing of a template.
◆ twig_localized_currency_filter()
twig_localized_currency_filter |
( |
|
$number, |
|
|
|
$currency = null , |
|
|
|
$locale = null |
|
) |
| |
Definition at line 85 of file Intl.php.
References twig_get_number_formatter().
89 return $formatter->formatCurrency($number, $currency);
twig_get_number_formatter($locale, $style)
Gets a number formatter instance according to given locale and formatter.
◆ twig_localized_date_filter()
twig_localized_date_filter |
( |
Twig_Environment |
$env, |
|
|
|
$date, |
|
|
|
$dateFormat = 'medium' , |
|
|
|
$timeFormat = 'medium' , |
|
|
|
$locale = null , |
|
|
|
$timezone = null , |
|
|
|
$format = null , |
|
|
|
$calendar = 'gregorian' |
|
) |
| |
Definition at line 42 of file Intl.php.
References $calendar, $format, and twig_date_converter().
Referenced by Twig_Tests_Extension_IntlTest\testLocalizedDateFilterWithDateTimeZone().
46 $formatValues = array(
47 'none' => IntlDateFormatter::NONE,
48 'short' => IntlDateFormatter::SHORT,
49 'medium' => IntlDateFormatter::MEDIUM,
50 'long' => IntlDateFormatter::LONG,
51 'full' => IntlDateFormatter::FULL,
54 $formatter = IntlDateFormatter::create(
56 $formatValues[$dateFormat],
57 $formatValues[$timeFormat],
58 PHP_VERSION_ID >= 50500 ? $date->getTimezone() : $date->getTimezone()->getName(),
59 'gregorian' ===
$calendar ? IntlDateFormatter::GREGORIAN : IntlDateFormatter::TRADITIONAL,
63 return $formatter->format($date->getTimestamp());
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
◆ twig_localized_number_filter()
twig_localized_number_filter |
( |
|
$number, |
|
|
|
$style = 'decimal' , |
|
|
|
$type = 'default' , |
|
|
|
$locale = null |
|
) |
| |
Definition at line 66 of file Intl.php.
References $style, $type, and twig_get_number_formatter().
68 static $typeValues = array(
69 'default' => NumberFormatter::TYPE_DEFAULT,
70 'int32' => NumberFormatter::TYPE_INT32,
71 'int64' => NumberFormatter::TYPE_INT64,
72 'double' => NumberFormatter::TYPE_DOUBLE,
73 'currency' => NumberFormatter::TYPE_CURRENCY,
78 if (!isset($typeValues[
$type])) {
79 throw new Twig_Error_Syntax(sprintf(
'The type "%s" does not exist. Known types are: "%s"', $type, implode(
'", "', array_keys($typeValues))));
82 return $formatter->format($number, $typeValues[$type]);
Exception thrown when a syntax error occurs during lexing or parsing of a template.
twig_get_number_formatter($locale, $style)
Gets a number formatter instance according to given locale and formatter.