Skip to main content

Intl Filters

Internationalization filters using PHP's Intl extension. These filters are only available when the PHP intl extension is loaded.

Name Lookups​

FilterArgumentsDescription
country_namelocaleGet country name from code
currency_namelocaleGet currency name from code
currency_symbollocaleGet currency symbol from code
language_namelocaleGet language name from code
locale_namelocaleGet locale name from code
timezone_namelocaleGet timezone name from identifier

All filters accept an optional locale argument (defaults to WordPress locale).

{{ 'US'|country_name }}                        <!-- United States -->
{{ 'FR'|country_name }} <!-- France -->
{{ 'FR'|country_name('fr_FR') }} <!-- France (in French) -->

{{ 'USD'|currency_name }} <!-- US Dollar -->
{{ 'EUR'|currency_name }} <!-- Euro -->

{{ 'USD'|currency_symbol }} <!-- $ -->
{{ 'EUR'|currency_symbol }} <!-- € -->

{{ 'en'|language_name }} <!-- English -->
{{ 'fr'|language_name }} <!-- French -->
{{ 'fr'|language_name('fr_FR') }} <!-- français -->

{{ 'en_US'|locale_name }} <!-- English (United States) -->
{{ 'fr_FR'|locale_name }} <!-- French (France) -->

{{ 'Europe/Paris'|timezone_name }} <!-- Central European Standard Time -->
{{ 'America/New_York'|timezone_name }} <!-- Eastern Standard Time -->

Number Formatting​

FilterArgumentsDescription
format_currencycurrency, attrs, localeFormat as currency
format_numberattrs, style, type, localeFormat number

The arguments are those of Twig's Intl extension, in its order. Give the locale by its name to skip the others: format_currency('EUR', locale: 'de_DE').

format_currency​

Arguments:

  • currency — Currency code (default: 'USD')
  • attrs — Formatter attributes, as for format_number (optional)
  • locale — Locale code (default: WordPress locale)
{{ 1234.56|format_currency('USD') }}                   <!-- $1,234.56 -->
{{ 1234.56|format_currency('EUR') }} <!-- €1,234.56 -->
{{ 1234.56|format_currency('EUR', locale: 'de_DE') }} <!-- 1.234,56 € -->
{{ 1234.56|format_currency('GBP', locale: 'en_GB') }} <!-- £1,234.56 -->
{{ 1234.56|format_currency('EUR', {max_fraction_digit: 0}) }} <!-- €1,235 -->

format_number​

Arguments:

  • attrs — Formatter attributes (optional): grouping_used, decimal_always_shown, min_integer_digit, max_integer_digit, integer_digit, min_fraction_digit, max_fraction_digit, fraction_digit, multiplier, grouping_size, secondary_grouping_size, rounding_mode ('ceiling', 'floor', 'down', 'up', 'halfeven', 'halfdown', 'halfup'), rounding_increment, format_width, padding_position ('before_prefix', 'after_prefix', 'before_suffix', 'after_suffix'), significant_digits_used, min_significant_digits_used, max_significant_digits_used, lenient_parse
  • style — Format style (default: 'decimal')
  • type — 'default', 'int32', 'int64' or 'double' (default: 'default')
  • locale — Locale code (default: WordPress locale)

Style options:

  • 'decimal' — Standard decimal number
  • 'currency' — Currency format
  • 'percent' — Percentage format
  • 'scientific' — Scientific notation
  • 'spellout' — Number spelled out in words
  • 'ordinal' — Ordinal format (1st, 2nd, 3rd)
  • 'duration' — Duration format
{{ 1234.56|format_number }}                              <!-- 1,234.56 -->
{{ 1234.5678|format_number({max_fraction_digit: 2}) }} <!-- 1,234.57 -->
{{ 0.75|format_number(style: 'percent') }} <!-- 75% -->
{{ 1234|format_number(style: 'spellout') }} <!-- one thousand two hundred thirty-four -->
{{ 3|format_number(style: 'ordinal') }} <!-- 3rd -->

Date/Time Formatting​

FilterArgumentsDescription
format_datedate_format, pattern, timezone, calendar, localeFormat date
format_timetime_format, pattern, timezone, calendar, localeFormat time
format_datetimedate_format, time_format, pattern, timezone, calendar, localeFormat date and time

Format options:

  • 'none' — No output
  • 'short' — Short format
  • 'medium' — Medium format (default)
  • 'long' — Long format
  • 'full' — Full format

Give them a timestamp such as post.timestamp: post.date is already formatted and has no time. An empty value is now, as in Twig.

  • pattern — An ICU pattern, such as 'yyyy-MM-dd', instead of the formats
  • timezone — Timezone name (default: the site's); false keeps a date's own, and reads a timestamp in UTC, as in Twig
  • calendar — 'gregorian' (default) or 'traditional', the locale's own calendar
  • locale — Locale code (default: WordPress locale)

format_date​

{{ post.timestamp|format_date }}                    <!-- Jan 15, 2024 -->
{{ post.timestamp|format_date('short') }} <!-- 1/15/24 -->
{{ post.timestamp|format_date('medium') }} <!-- Jan 15, 2024 -->
{{ post.timestamp|format_date('long') }} <!-- January 15, 2024 -->
{{ post.timestamp|format_date('full') }} <!-- Monday, January 15, 2024 -->
{{ post.timestamp|format_date('long', locale: 'fr_FR') }} <!-- 15 janvier 2024 -->
{{ post.timestamp|format_date(pattern: 'yyyy-MM-dd') }} <!-- 2024-01-15 -->

format_time​

{{ post.timestamp|format_time }}                    <!-- 2:30:00 PM -->
{{ post.timestamp|format_time('short') }} <!-- 2:30 PM -->
{{ post.timestamp|format_time('medium') }} <!-- 2:30:00 PM -->
{{ post.timestamp|format_time('long') }} <!-- 2:30:00 PM EST -->

format_datetime​

{{ post.timestamp|format_datetime }}
{{ post.timestamp|format_datetime('medium', 'short') }}
{{ post.timestamp|format_datetime('long', 'short', locale: 'fr_FR') }}
{{ post.timestamp|format_datetime(timezone: 'Asia/Tokyo') }}

Common Patterns​

Localized currency display​

{{ product.price|format_currency('USD') }}

Localized date​

{{ post.timestamp|format_date('long') }}

Country selector label​

{{ country_code|country_name }}