aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/Twig/Extensions/Extension/Intl.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
commita4565e88edbc8e3bd092a475469769c86a4c350c (patch)
treea6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /inc/Twig/Extensions/Extension/Intl.php
parentf6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff)
downloadwallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip
add Twig & refactor poche
Diffstat (limited to 'inc/Twig/Extensions/Extension/Intl.php')
-rw-r--r--inc/Twig/Extensions/Extension/Intl.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/inc/Twig/Extensions/Extension/Intl.php b/inc/Twig/Extensions/Extension/Intl.php
new file mode 100644
index 00000000..40f7fc20
--- /dev/null
+++ b/inc/Twig/Extensions/Extension/Intl.php
@@ -0,0 +1,66 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12class Twig_Extensions_Extension_Intl extends Twig_Extension
13{
14 public function __construct()
15 {
16 if (!class_exists('IntlDateFormatter')) {
17 throw new RuntimeException('The intl extension is needed to use intl-based filters.');
18 }
19 }
20
21 /**
22 * Returns a list of filters to add to the existing list.
23 *
24 * @return array An array of filters
25 */
26 public function getFilters()
27 {
28 return array(
29 'localizeddate' => new Twig_Filter_Function('twig_localized_date_filter', array('needs_environment' => true)),
30 );
31 }
32
33 /**
34 * Returns the name of the extension.
35 *
36 * @return string The extension name
37 */
38 public function getName()
39 {
40 return 'intl';
41 }
42}
43
44function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
45{
46 $date = twig_date_converter($env, $date, $timezone);
47
48 $formatValues = array(
49 'none' => IntlDateFormatter::NONE,
50 'short' => IntlDateFormatter::SHORT,
51 'medium' => IntlDateFormatter::MEDIUM,
52 'long' => IntlDateFormatter::LONG,
53 'full' => IntlDateFormatter::FULL,
54 );
55
56 $formatter = IntlDateFormatter::create(
57 $locale !== null ? $locale : Locale::getDefault(),
58 $formatValues[$dateFormat],
59 $formatValues[$timeFormat],
60 $date->getTimezone()->getName(),
61 IntlDateFormatter::GREGORIAN,
62 $format
63 );
64
65 return $formatter->format($date->getTimestamp());
66}