twig/intl-extra
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
symfony/intl | v7.0.7 | - | MIT | prod | |
twig/twig | v3.10.3 | - | BSD-3-Clause | prod |
The twig/intl-extra is a valuable composer package that acts as an extension for Twig, primarily aimed at handling internationalization elements within your project. This includes formatting for numbers, dates, times, and currencies, including localization for specific country and language names. It also has the ability to handle country-specific timezone identifiers and offer detailed information about currency, including the name and symbol.
Using twig/intl-extra in your PHP project is accomplished like any other Twig extension.
To begin with, you need to install the package via Composer using the command:
composer require twig/intl-extra
Next, enable the extension in your Twig environment. An example implementation could be:
$twig = new \Twig\Environment($loader);
$twig->addExtension(new Twig\Extra\Intl\IntlExtension());
This gives you access to several Twig filters that you can incorporate into your templates. For instance, if you want to format a number as a currency or get a country name from a given code, you can do:
{{ 'US'|country_name }}
{{ 1000000|format_currency('USD', 'en_US') }}
In the first line, 'US' is the two-letter code for the United States, while in the second line, '1000000' is the number to be formatted, 'USD' is the currency code, and 'en_US' is the locale.
Detailed documentation for the twig/intl-extra package is available directly through the Twig Symfony website. The site features a comprehensive breakdown for each filter provided by the package, including country_name
, currency_name
, currency_symbol
, language_name
, locale_name
, timezone_name
, country_timezones
, format_currency
, format_number
, format_datetime
, format_date
, and format_time
. The respecive links for documentation of these filters are provided in the readme file, each filter's description can be accessed using its specific link. For example, to learn more about the country_name
filter, you can visit twig.symfony.com/country_name.