Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #3742 Add function twig *_name for intl (seb-jean, fabpot)
This PR was merged into the 3.x branch. Discussion ---------- Add function twig *_name for intl Hi, I add `language_names`, `script_names`, `country_names`, `locale_names`, `currency_names`, `timezone_names`. It allows us to have a list but on the Twig side and to use them in filters for example. Commits ------- 6f9c7c0 Fix tests b376bdd Add function twig *_name for intl list
- Loading branch information
Showing
13 changed files
with
440 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``country_names`` | ||
================= | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``country_names`` function was added in Twig 3.5. | ||
|
||
The ``country_names`` function returns the names of the countries: | ||
|
||
.. code-block:: twig | ||
{# Afghanistan, Åland Islands, ... #} | ||
{{ country_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# Afghanistan, Afrique du Sud, ... #} | ||
{{ country_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``country_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``currency_names`` | ||
================== | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``currency_names`` function was added in Twig 3.5. | ||
|
||
The ``currency_names`` function returns the names of the currencies: | ||
|
||
.. code-block:: twig | ||
{# Afghan Afghani, Afghan Afghani (1927–2002), ... #} | ||
{{ currency_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# afghani (1927–2002), afghani afghan, ... #} | ||
{{ currency_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``currency_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``language_names`` | ||
================== | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``language_names`` function was added in Twig 3.5. | ||
|
||
The ``language_names`` function returns the names of the languages: | ||
|
||
.. code-block:: twig | ||
{# Abkhazian, Achinese, ... #} | ||
{{ language_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# abkhaze, aceh, ... #} | ||
{{ language_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``language_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``locale_names`` | ||
================ | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``locale_names`` function was added in Twig 3.5. | ||
|
||
The ``locale_names`` function returns the names of the locales: | ||
|
||
.. code-block:: twig | ||
{# Afrikaans, Afrikaans (Namibia), ... #} | ||
{{ locale_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# afrikaans, afrikaans (Afrique du Sud), ... #} | ||
{{ locale_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``locale_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``script_names`` | ||
================ | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``script_names`` function was added in Twig 3.5. | ||
|
||
The ``script_names`` function returns the names of the scripts: | ||
|
||
.. code-block:: twig | ||
{# Adlam, Afaka, ... #} | ||
{{ script_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# Adlam, Afaka, ... #} | ||
{{ script_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``script_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
``timezone_names`` | ||
================== | ||
|
||
.. versionadded:: 3.5 | ||
|
||
The ``timezone_names`` function was added in Twig 3.5. | ||
|
||
The ``timezone_names`` function returns the names of the timezones: | ||
|
||
.. code-block:: twig | ||
{# Acre Time (Eirunepe), Acre Time (Rio Branco), ... #} | ||
{{ timezone_names()|join(', ') }} | ||
By default, the function uses the current locale. You can pass it explicitly: | ||
|
||
.. code-block:: twig | ||
{# heure : Antarctique (Casey), heure : Canada (Montreal), ... #} | ||
{{ timezone_names('fr')|join(', ') }} | ||
.. note:: | ||
|
||
The ``timezone_names`` function is part of the ``IntlExtension`` which is not | ||
installed by default. Install it first: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/intl-extra | ||
Then, on Symfony projects, install the ``twig/extra-bundle``: | ||
|
||
.. code-block:: bash | ||
$ composer require twig/extra-bundle | ||
Otherwise, add the extension explicitly on the Twig environment:: | ||
|
||
use Twig\Extra\Intl\IntlExtension; | ||
|
||
$twig = new \Twig\Environment(...); | ||
$twig->addExtension(new IntlExtension()); | ||
|
||
Arguments | ||
--------- | ||
|
||
* ``locale``: The locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
"country_names" function | ||
--TEMPLATE-- | ||
{{ country_names('UNKNOWN')|length }} | ||
{{ country_names()|length }} | ||
{{ country_names('fr')|length }} | ||
{{ country_names()['BE'] }} | ||
{{ country_names('fr')['BE'] }} | ||
--DATA-- | ||
return []; | ||
--EXPECT-- | ||
0 | ||
249 | ||
249 | ||
Belgium | ||
Belgique |
Oops, something went wrong.