mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 18:06:46 +00:00
Move country_timezone to a function
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
* added the Inky extension in the "extra" repositories: "inky" filter
|
||||
* added Intl extension in the "extra" repositories: "country_name",
|
||||
"currency_name", "currency_symbol", "language_name", "locale_name",
|
||||
"timezone_name", "country_timezones", "format_currency", "format_number",
|
||||
"timezone_name", "format_currency", "format_number",
|
||||
"format_*_number", "format_datetime", "format_date", and "format_time"
|
||||
filters
|
||||
filters, and the "country_timezones" function
|
||||
* added the Markdown extension in the "extra" repositories: "markdown_to_html",
|
||||
and "html_to_markdown" filters
|
||||
* added the HtmlExtension extension in the "extra" repositories: "date_uri"
|
||||
|
||||
@@ -10,7 +10,6 @@ Filters
|
||||
column
|
||||
convert_encoding
|
||||
country_name
|
||||
country_timezones
|
||||
currency_name
|
||||
currency_symbol
|
||||
data_uri
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
=====================
|
||||
|
||||
.. versionadded:: 2.12
|
||||
The ``country_timezones`` filter was added in Twig 2.12.
|
||||
The ``country_timezones`` function was added in Twig 2.12.
|
||||
|
||||
The ``country_timezones`` filter returns the names of the timezones associated
|
||||
The ``country_timezones`` function returns the names of the timezones associated
|
||||
with a given country code:
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{# Europe/Paris #}
|
||||
{{ 'FR'|country_timezones|join(', ') }}
|
||||
{{ country_timezones('FR')|join(', ') }}
|
||||
|
||||
.. note::
|
||||
|
||||
The ``country_timezones`` filter is part of the ``IntlExtension`` which is not
|
||||
The ``country_timezones`` function is part of the ``IntlExtension`` which is not
|
||||
installed by default. Install it first:
|
||||
|
||||
.. code-block:: bash
|
||||
@@ -18,4 +18,5 @@ Functions
|
||||
random
|
||||
range
|
||||
source
|
||||
country_timezones
|
||||
template_from_string
|
||||
|
||||
@@ -20,6 +20,7 @@ use Twig\Environment;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
final class IntlExtension extends AbstractExtension
|
||||
{
|
||||
@@ -134,7 +135,6 @@ final class IntlExtension extends AbstractExtension
|
||||
new TwigFilter('language_name', [$this, 'getLanguageName']),
|
||||
new TwigFilter('locale_name', [$this, 'getLocaleName']),
|
||||
new TwigFilter('timezone_name', [$this, 'getTimezoneName']),
|
||||
new TwigFilter('country_timezones', [$this, 'getCountryTimezones']),
|
||||
|
||||
// localized formatters
|
||||
new TwigFilter('format_currency', [$this, 'formatCurrency']),
|
||||
@@ -146,6 +146,14 @@ final class IntlExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
// internationalized names
|
||||
new TwigFunction('country_timezones', [$this, 'getCountryTimezones']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getCountryName(string $country, string $locale = null): string
|
||||
{
|
||||
return Countries::getName($country, $locale);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
--TEST--
|
||||
"country_timezones" filter
|
||||
"country_timezones" function
|
||||
--TEMPLATE--
|
||||
{{ 'FR'|country_timezones|join(', ') }}
|
||||
{{ 'US'|country_timezones|join(', ') }}
|
||||
{{ country_timezones('FR')|join(', ') }}
|
||||
{{ country_timezones('US')|join(', ') }}
|
||||
--DATA--
|
||||
return [];
|
||||
--EXPECT--
|
||||
|
||||
@@ -41,12 +41,12 @@ final class Extensions
|
||||
'class' => IntlExtension::class,
|
||||
'class_name' => 'IntlExtension',
|
||||
'package' => 'twig/intl-extra',
|
||||
'filters' => ['country_name', 'currency_name', 'currency_symbol', 'language_name', 'country_timezones',
|
||||
'filters' => ['country_name', 'currency_name', 'currency_symbol', 'language_name',
|
||||
'format_currency', 'format_number', 'format_decimal_number', 'format_currency_number',
|
||||
'format_percent_number', 'format_scientific_number', 'format_spellout_number', 'format_ordinal_number',
|
||||
'format_duration_number', 'format_date', 'format_datetime', 'format_time',
|
||||
],
|
||||
'functions' => [],
|
||||
'functions' => ['country_timezones'],
|
||||
],
|
||||
'cssinliner' => [
|
||||
'name' => 'cssinliner',
|
||||
|
||||
Reference in New Issue
Block a user