Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``timezone_name`` |
| 2 | ================= |
| 3 | |
| 4 | The ``timezone_name`` filter returns the timezone name given a timezone identifier: |
| 5 | |
| 6 | .. code-block:: twig |
| 7 | |
| 8 | {# Central European Time (Paris) #} |
| 9 | {{ 'Europe/Paris'|timezone_name }} |
| 10 | |
| 11 | {# Pacific Time (Los Angeles) #} |
| 12 | {{ 'America/Los_Angeles'|timezone_name }} |
| 13 | |
| 14 | By default, the filter uses the current locale. You can pass it explicitly: |
| 15 | |
| 16 | .. code-block:: twig |
| 17 | |
| 18 | {# heure du Pacifique nord-américain (Los Angeles) #} |
| 19 | {{ 'America/Los_Angeles'|timezone_name('fr') }} |
| 20 | |
| 21 | .. note:: |
| 22 | |
| 23 | The ``timezone_name`` filter is part of the ``IntlExtension`` which is not |
| 24 | installed by default. Install it first: |
| 25 | |
| 26 | .. code-block:: bash |
| 27 | |
| 28 | $ composer require twig/intl-extra |
| 29 | |
| 30 | Then, on Symfony projects, install the ``twig/extra-bundle``: |
| 31 | |
| 32 | .. code-block:: bash |
| 33 | |
| 34 | $ composer require twig/extra-bundle |
| 35 | |
| 36 | Otherwise, add the extension explicitly on the Twig environment:: |
| 37 | |
| 38 | use Twig\Extra\Intl\IntlExtension; |
| 39 | |
| 40 | $twig = new \Twig\Environment(...); |
| 41 | $twig->addExtension(new IntlExtension()); |
| 42 | |
| 43 | Arguments |
| 44 | --------- |
| 45 | |
| 46 | * ``locale``: The locale |