1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoS\ResourceBundle\Twig\Extension; |
4
|
|
|
|
5
|
|
|
class Intl extends \Twig_Extensions_Extension_Intl |
6
|
|
|
{ |
7
|
|
|
protected $traditional = true; |
8
|
|
|
|
9
|
|
|
public function __construct($traditional = true) |
10
|
|
|
{ |
11
|
|
|
parent::__construct(); |
12
|
|
|
|
13
|
|
|
$this->traditional = $traditional; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function getFilters() |
17
|
|
|
{ |
18
|
|
|
return array( |
19
|
|
|
new \Twig_SimpleFilter('localizeddate', array($this, 'twig_localized_date_filter'), array('needs_environment' => true)), |
|
|
|
|
20
|
|
|
new \Twig_SimpleFilter('localizednumber', 'twig_localized_number_filter'), |
|
|
|
|
21
|
|
|
new \Twig_SimpleFilter('localizedcurrency', 'twig_localized_currency_filter'), |
|
|
|
|
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function twig_localized_date_filter(\Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) |
26
|
|
|
{ |
27
|
|
|
$date = twig_date_converter($env, $date, $timezone); |
28
|
|
|
|
29
|
|
|
$formatValues = array( |
30
|
|
|
'none' => \IntlDateFormatter::NONE, |
31
|
|
|
'short' => \IntlDateFormatter::SHORT, |
32
|
|
|
'medium' => \IntlDateFormatter::MEDIUM, |
33
|
|
|
'long' => \IntlDateFormatter::LONG, |
34
|
|
|
'full' => \IntlDateFormatter::FULL, |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$formatter = \IntlDateFormatter::create( |
38
|
|
|
$locale, |
39
|
|
|
$formatValues[$dateFormat], |
40
|
|
|
$formatValues[$timeFormat], |
41
|
|
|
$date->getTimezone()->getName(), |
42
|
|
|
$this->traditional ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN, |
43
|
|
|
$format |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
return $formatter->format($date->getTimestamp()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.