The Intl Extension

The Intl extensions provides the localizeddate, localizednumber and localizedcurrency filters.

Installation

First, install the Extensions library. Next, add the extension to Twig:

$twig->addExtension(new Twig_Extensions_Extension_Intl());

localizeddate

Use the localizeddate filter to format dates into a localized string representating the date.

{{ post.published_at|localizeddate('medium', 'none', locale) }}

The localizeddate filter accepts strings (it must be in a format supported by the strtotime function), DateTime instances, or Unix timestamps.

Note

Internally, Twig uses the PHP IntlDateFormatter::create() function for the date.

Arguments

For the following calendars should use ‘traditional’:
  • Japanese
  • Buddhist
  • Chinese
  • Persian
  • Indian
  • Islamic
  • Hebrew
  • Indian
  • Coptic
  • Ethiopic

Also for non-Gregorian calendars need to be specified in locale. Examples might include locale=”fa_IR@calendar=PERSIAN”.

localizednumber

Use the localizednumber filter to format numbers into a localized string representating the number.

{{ product.quantity|localizednumber }}

Note

Internally, Twig uses the PHP NumberFormatter::create() function for the number.

Arguments

localizedcurrency

Use the localizedcurrency filter to format a currency value into a localized string.

{{ product.price|localizedcurrency('EUR') }}

Note

Internally, Twig uses the PHP NumberFormatter::create() function for the number.

Arguments

  • currency: The 3-letter ISO 4217 currency code indicating the currency to use.
  • locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()