Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Latest commit

 

History

History
162 lines (115 loc) · 6.46 KB

intl.rst

File metadata and controls

162 lines (115 loc) · 6.46 KB

The Intl Extension

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

Installation

First, :ref:`install the Extensions library<extensions-install>`. Next, add the extension to Twig:

use Twig\Extensions\IntlExtension;

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

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
  • 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()