alaczi / twig-locale-name-extension
Twig locale name filter extension for twig
Installs: 4 030
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- symfony/intl: ~2.3|~3.0
- twig/twig: ~1.15
This package is auto-updated.
Last update: 2024-10-25 23:53:55 UTC
README
This twig extension is to write the human readable names of the 2 or 5 letter locale codes (eg: en or en_GB)
Ideal to use with the language picker as you can pass the locale as second parameter to display the locale name on that language
Require as dependency
composer require alaczi/twig-locale-name-extension
Register the extension
PHP
$filter = new \alaczi\Twig\Extension\LocaleNameExtension(); $twig = new Twig_Environment($loader); $twig->addFilter($filter);
Symfony 2
services: alaczi.twig.country_extension: class: alaczi\Twig\Extension\LocaleNameExtension tags: - { name: twig.extension }
Silex
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) { /** @var \Twig_Environment $twig */ $twig->addExtension(new \alaczi\Twig\Extension\LocaleNameExtension()) return $twig; }));
Usage in twig
Using the current locale:
{{ locale|locale_name }}
Using an other locale (eg: for language pickers)
{{ locale|locale_name(locale) }}