anezi / locale-extension
Locale Extensions for Twig
1.2.1
2020-12-13 21:20 UTC
Requires
- php: >=7.1
- ext-intl: *
- symfony/intl: >=2.6.0
- twig/twig: >=2.10.0
Requires (Dev)
- phpunit/phpunit: ^7.5 | ^8.0
README
Installation
The extension is installable via composer:
composer require anezi/locale-extension
Symfony service
services: anezi_twig.locale_extension: class: Anezi\Locale\Twig\Extension\LocaleExtension public: false arguments: ["%managed_locales%"] tags: - { name: twig.extension }
Functions
Get locales
{% for locale in locales() %}{{ locale }} - {% endfor %}
shows:
ar - en - fr -
Filters
Get country name
{{ "be"|country_name }}
shows:
Belgium
Get locale name
{{ "fr_BE"|locale_name }}
shows:
French (Belgium)
Get locale name in that locale
{{ "fr_BE"|origin_locale_name }}
shows:
français (Belgique)
Get locale short name
{{ "fr_BE"|locale_short_name }}
shows:
fr
Get html direction
{{ "ar"|html_dir }}
shows:
rtl