MessageFormatter
in package
Provides the ability to process ICU MessageFormat strings, regardless whether the host has the intl extension installed.
Table of Contents
Constants
- CURRENCY_SYMBOLS = ['AUD' => 'A$', 'BRL' => 'R$', 'CAD' => 'CA$', 'CNY' => 'CN¥', 'EUR' => '€', 'GBP' => '£', 'HKD' => 'HK$', 'ILS' => '₪', 'INR' => '₹', 'JPY' => '¥', 'KRW' => '₩', 'MXN' => 'MX$', 'NZD' => 'NZ$', 'PHP' => '₱', 'TWD' => 'NT$', 'USD' => 'US$', 'VND' => '₫', 'XAF' => 'FCFA', 'XCD' => 'EC$', 'XOF' => "F CFA", 'XPF' => 'CFPF']
- Official, unambiguous, long-form symbols for certain currencies.
Properties
- $plural_rules : array<string|int, mixed>
- $message_formatters : array<string|int, mixed>
Methods
- formatMessage() : string
- Formats a MessageFormat string using the supplied arguments.
- applyNumberSkeleton() : string
- Formats a number according to ICU 60+ NumberFormatter "skeletons".
- getPluralizationCategory() : string
- Gets the correct pluralization category to use for a number in the current language.
Constants
CURRENCY_SYMBOLS
Official, unambiguous, long-form symbols for certain currencies.
public
mixed
CURRENCY_SYMBOLS
= ['AUD' => 'A$', 'BRL' => 'R$', 'CAD' => 'CA$', 'CNY' => 'CN¥', 'EUR' => '€', 'GBP' => '£', 'HKD' => 'HK$', 'ILS' => '₪', 'INR' => '₹', 'JPY' => '¥', 'KRW' => '₩', 'MXN' => 'MX$', 'NZD' => 'NZ$', 'PHP' => '₱', 'TWD' => 'NT$', 'USD' => 'US$', 'VND' => '₫', 'XAF' => 'FCFA', 'XCD' => 'EC$', 'XOF' => "F CFA", 'XPF' => 'CFPF']
Note that not all currencies have long-form symbols. For currencies that do not have long-form symbols, the raw currency code is used instead.
Properties
$plural_rules
public
static array<string|int, mixed>
$plural_rules
Rules for determining the correct pluralization category to use for any given number in any given language.
$message_formatters
private
static array<string|int, mixed>
$message_formatters
= []
Instances of \MessageFormatter.
Methods
formatMessage()
Formats a MessageFormat string using the supplied arguments.
public
static formatMessage(string $message[, array<string|int, mixed> $args = [] ]) : string
Parameters
- $message : string
-
The MessageFormat string.
- $args : array<string|int, mixed> = []
-
Arguments to use in the MessageFormat string.
Return values
string —The formatted string.
applyNumberSkeleton()
Formats a number according to ICU 60+ NumberFormatter "skeletons".
protected
static applyNumberSkeleton(int|float|string $number, istring $skeleton) : string
https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html
NumberFormatter skeletons are different from, and more flexible than, the legacy NumberFormat system that is supported by the intl extension's NumberFormatter class. Moreover, support for skeletons is incorporated directly into MessageFormatter, removing the need for a separate class.
This method supports a subset of all NumberFormatter skeletons. Unsupported skeletons include those for formatting measurement units, accounting notation, special rounding precision modes for handling cash in certain currencies, and alternative numbering systems. None of these are necessary for SMF's needs, so the supported subset is sufficient to support SMF on servers that do not have the intl extension installed.
Parameters
- $number : int|float|string
-
A number.
- $skeleton : istring
-
The ICU number skeleton.
Return values
string —A formatted number.
getPluralizationCategory()
Gets the correct pluralization category to use for a number in the current language.
protected
static getPluralizationCategory(int|float|string $num[, string $type = 'cardinal' ]) : string
Parameters
- $num : int|float|string
-
The number.
- $type : string = 'cardinal'
-
Either 'cardinal' or 'ordinal'. Default: 'cardinal'.
Return values
string —The pluralization category to use.