ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Intl.php File Reference

Go to the source code of this file.

Data Structures

class  Twig_Extensions_Extension_Intl
 

Functions

 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...
 

Function Documentation

◆ twig_get_number_formatter()

twig_get_number_formatter (   $locale,
  $style 
)

Gets a number formatter instance according to given locale and formatter.

Parameters
string$localeLocale in which the number would be formatted
int$styleStyle of the formatting
Returns
NumberFormatter A NumberFormatter instance

Definition at line 100 of file Intl.php.

References $style, and array.

Referenced by twig_localized_currency_filter(), and twig_localized_number_filter().

101 {
102  static $formatter, $currentStyle;
103 
104  $locale = $locale !== null ? $locale : Locale::getDefault();
105 
106  if ($formatter && $formatter->getLocale() === $locale && $currentStyle === $style) {
107  // Return same instance of NumberFormatter if parameters are the same
108  // to those in previous call
109  return $formatter;
110  }
111 
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,
120  );
121 
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))));
124  }
125 
126  $currentStyle = $style;
127 
128  $formatter = NumberFormatter::create($locale, $styleValues[$style]);
129 
130  return $formatter;
131 }
$style
Definition: example_012.php:70
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ 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().

86 {
87  $formatter = twig_get_number_formatter($locale, 'currency');
88 
89  return $formatter->formatCurrency($number, $currency);
90 }
twig_get_number_formatter($locale, $style)
Gets a number formatter instance according to given locale and formatter.
Definition: Intl.php:100
+ Here is the call graph for this function:

◆ 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 $format, array, and twig_date_converter().

Referenced by Twig_Tests_Extension_IntlTest\testLocalizedDateFilterWithDateTimeZone().

43 {
44  $date = twig_date_converter($env, $date, $timezone);
45 
46  $formatValues = array(
47  'none' => IntlDateFormatter::NONE,
48  'short' => IntlDateFormatter::SHORT,
49  'medium' => IntlDateFormatter::MEDIUM,
50  'long' => IntlDateFormatter::LONG,
51  'full' => IntlDateFormatter::FULL,
52  );
53 
54  $formatter = IntlDateFormatter::create(
55  $locale,
56  $formatValues[$dateFormat],
57  $formatValues[$timeFormat],
58  PHP_VERSION_ID >= 50500 ? $date->getTimezone() : $date->getTimezone()->getName(),
59  'gregorian' === $calendar ? IntlDateFormatter::GREGORIAN : IntlDateFormatter::TRADITIONAL,
60  $format
61  );
62 
63  return $formatter->format($date->getTimestamp());
64 }
$format
Definition: metadata.php:141
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
Definition: Core.php:422
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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, array, and twig_get_number_formatter().

67 {
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,
74  );
75 
76  $formatter = twig_get_number_formatter($locale, $style);
77 
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))));
80  }
81 
82  return $formatter->format($number, $typeValues[$type]);
83 }
$style
Definition: example_012.php:70
$type
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
twig_get_number_formatter($locale, $style)
Gets a number formatter instance according to given locale and formatter.
Definition: Intl.php:100
Create styles array
The data for the language used.
+ Here is the call graph for this function: