4 * This file is part of Twig.
6 * (c) 2010 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Extensions_Extension_Intl
extends Twig_Extension
14 public function __construct()
16 if (!class_exists('IntlDateFormatter')) {
17 throw new RuntimeException('The intl extension is needed to use intl-based filters.');
22 * Returns a list of filters to add to the existing list.
24 * @return array An array of filters
26 public function getFilters()
29 'localizeddate' => new Twig_Filter_Function('twig_localized_date_filter', array('needs_environment' => true)),
34 * Returns the name of the extension.
36 * @return string The extension name
38 public function getName()
44 function twig_localized_date_filter(Twig_Environment
$env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
46 $date = twig_date_converter($env, $date, $timezone);
48 $formatValues = array(
49 'none' => IntlDateFormatter
::NONE
,
50 'short' => IntlDateFormatter
::SHORT
,
51 'medium' => IntlDateFormatter
::MEDIUM
,
52 'long' => IntlDateFormatter
::LONG
,
53 'full' => IntlDateFormatter
::FULL
,
56 $formatter = IntlDateFormatter
::create(
57 $locale !== null ? $locale : Locale
::getDefault(),
58 $formatValues[$dateFormat],
59 $formatValues[$timeFormat],
60 $date->getTimezone()->getName(),
61 IntlDateFormatter
::GREGORIAN
,
65 return $formatter->format($date->getTimestamp());