Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alaczi/twig-locale-name-extension
Locale name extension for TWIG
https://github.com/alaczi/twig-locale-name-extension
symphony twig twig-extension
Last synced: 21 days ago
JSON representation
Locale name extension for TWIG
- Host: GitHub
- URL: https://github.com/alaczi/twig-locale-name-extension
- Owner: alaczi
- Created: 2016-02-29T16:03:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-21T12:04:40.000Z (almost 8 years ago)
- Last Synced: 2024-02-14T22:35:04.437Z (4 months ago)
- Topics: symphony, twig, twig-extension
- Language: PHP
- Size: 1.95 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Lists
- awesome-twig - LocaleName - Twig locale name filter extension for twig (Twig / Extensions)
- awesome-twig - LocaleName - Twig locale name filter extension for twig (Twig / Extensions)
README
# Usage
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
```bash
composer require alaczi/twig-locale-name-extension
```## Register the extension
### PHP
```php
$filter = new \alaczi\Twig\Extension\LocaleNameExtension();
$twig = new Twig_Environment($loader);
$twig->addFilter($filter);
```### Symfony 2
```yaml
services:
alaczi.twig.country_extension:
class: alaczi\Twig\Extension\LocaleNameExtension
tags:
- { name: twig.extension }
```### Silex
```php
$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:
```twig
{{ locale|locale_name }}
```Using an other locale (eg: for language pickers)
```twig
{{ locale|locale_name(locale) }}
```