Ecma\Intl\Locale

class Ecma\Intl\Locale

A Locale represents a Unicode locale identifier.

property baseName string | null, readonly

The baseName property is a substring containing this locale’s core information, including language, script, region, and variant information.

The baseName does not contain any of the locale’s keyword values.

property calendar string | null, readonly

The calendar property has the calendar type for this locale.

If neither the ca key of the locale identifier nor the Ecma\Intl\Locale\Options::$calendar option is set, this value is null.

property calendars string[], readonly

See Ecma\Intl\Locale::getCalendars().

property caseFirst string | null, readonly

The caseFirst property conveys whether case is taken into account for this locale’s collation rules.

The caseFirst property can have one of the following three values:

  • "upper", meaning upper case values are sorted before lower case.

  • "lower", meaning lower case values are sorted before upper case.

  • "false", meaning there is no special case ordering (this is a string value and not a boolean).

If neither the kf key of the locale identifier nor the Ecma\Intl\Locale\Options::$caseFirst option is set, this value is null.

property collation string | null, readonly

The collation property has the collation type for this locale.

The collation type is used to order strings according to the locale’s rules.

If neither the co key of the locale identifier nor the Ecma\Intl\Locale\Options::$collation option is set, this value is null.

property collations string[], readonly

See Ecma\Intl\Locale::getCollations().

property currencies string[], readonly

See Ecma\Intl\Locale::getCurrencies().

property currency string | null, readonly

The currency property has the currency type for this locale.

The currency type is the 3-character ISO 4217 currency code. If neither the cu key of the locale identifier nor the Ecma\Intl\Locale\Options::$currency option is set, this value is null.

This property is not defined in ECMA-402 or in the Intl Locale Info Proposal. Instead, this is unique to the PHP implementation and is inspired by the Intl Locale Info Proposal.

property hourCycle string | null, readonly

The hourCycle property has the hour cycle type for this locale.

The hourCycle property can have one of the following four values:

  • "h12", an hour system using 1-12 for a 12-hour clock, with midnight starting at 12:00 am.

  • "h23", an hour system using 0-23 for a 24-hour clock, with midnight starting at 0:00.

  • "h11", an hour system using 0-11 for a 12-hour clock, with midnight starting at 0:00 am.

  • "h24", an hour system using 1-24 for a 24-hour clock, with midnight starting at 24:00.

If neither the hc key of the locale identifier nor the Ecma\Intl\Locale\Options::$hourCycle option is set, this value is null.

property hourCycles string[], readonly

See Ecma\Intl\Locale::getHourCycles().

property language string | null, readonly

The language property has the language code for this locale.

In the case of an undefined language code (i.e., “und”), this value is null.

property numberingSystem string | null, readonly

The numberingSystem property has the numeral system for this locale.

If neither the nu key of the locale identifier nor the Ecma\Intl\Locale\Options::$numberingSystem option is set, this value is null.

property numberingSystems string[], readonly

See Ecma\Intl\Locale::getNumberingSystems().

property numeric bool, readonly

The numeric property conveys whether this locale has special collation handling for numeric characters.

property region string | null, readonly

The region property has the region code for this locale.

If neither the region part of the locale identifier nor the Ecma\Intl\Locale\Options::$region option is set, this value is null.

property script string | null, readonly

The script property has the script code for this locale.

If neither the script part of the locale identifier nor the Ecma\Intl\Locale\Options::$script option is set, this value is null.

property textInfo Ecma\Intl\Locale\TextInfo, readonly

See Ecma\Intl\Locale::getTextInfo().

property timeZones string[] | null, readonly

See Ecma\Intl\Locale::getTimeZones().

property weekInfo Ecma\Intl\Locale\WeekInfo, readonly

See Ecma\Intl\Locale::getWeekInfo().

__construct($tag[, $options = null])

Constructs an instance of a Unicode locale identifier.

Parameters:
  • $tag (Stringable | string) – The language tag (or locale identifier).

  • $options (Ecma\Intl\Locale\Options) – Additional options to apply to the locale. If the $tag already has values for any of the options provided, the values on the $options parameter will override those on the $tag.

__toString() string

Returns a string representation of the full locale identifier.

Alias of Ecma\Intl\Locale::toString().

getCalendars() string[]

Returns a list of one or more calendar types commonly used for this locale.

If the locale already includes a calendar (e.g., en-u-ca-buddhist) or one was provided via the constructor’s $options parameter, this list will contain only that calendar type.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named calendars, so most browsers implement this as Locale.calendars. However, recent drafts of this proposal have changed the design to the method Locale.getCalendars(). As a result, this implementation provides both Ecma\Intl\Locale::getCalendars() and Ecma\Intl\Locale::$calendars, each of which return the same value.

getCollations() string[]

Returns a list of one or more collation types commonly used for this locale.

If the locale already includes a collation (e.g., en-u-co-emoji) or one was provided via the constructor’s $options parameter, this list will contain only that collation type.

The standard and search collation types are always excluded from this list.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named collations, so most browsers implement this as Locale.collations. However, recent drafts of this proposal have changed the design to the method Locale.getCollations(). As a result, this implementation provides both Ecma\Intl\Locale::getCollations() and Ecma\Intl\Locale::$collations, each of which return the same value.

getCurrencies() string[]

Returns a list of one or more currency types commonly used for this locale.

If the locale already includes a currency (e.g., en-u-cu-eur) or one was provided via the constructor’s $options parameter, this list will contain only that currency type.

This method is not defined in ECMA-402 or in the Intl Locale Info Proposal in which other similar methods are described. Instead, this is unique to the PHP implementation and is inspired by the Intl Locale Info Proposal.

getHourCycles() string[]

Returns a list of one or more hour cycle types commonly used for this locale.

If the locale already includes an hour cycle (e.g., en-u-hc-h11) or one was provided via the constructor’s $options parameter, this list will contain only that hour cycle type.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named hourCycles, so most browsers implement this as Locale.hourCycles. However, recent drafts of this proposal have changed the design to the method Locale.getHourCycles(). As a result, this implementation provides both Ecma\Intl\Locale::getHourCycles() and Ecma\Intl\Locale::$hourCycles, each of which return the same value.

getNumberingSystems() string[]

Returns a list of one or more numbering systems commonly used for this locale.

If the locale already includes a numbering system (e.g., en-u-nu-arab) or one was provided via the constructor’s $options parameter, this list will contain only that numbering system.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named numberingSystems, so most browsers implement this as Locale.numberingSystems. However, recent drafts of this proposal have changed the design to the method Locale.getNumberingSystems(). As a result, this implementation provides both Ecma\Intl\Locale::getNumberingSystems() and Ecma\Intl\Locale::$numberingSystems, each of which return the same value.

getTextInfo() Ecma\Intl\Locale\TextInfo

Returns an Ecma\Intl\Locale\TextInfo object representing typesetting information for the locale.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named textInfo, so most browsers implement this as Locale.textInfo. However, recent drafts of this proposal have changed the design to the method Locale.getTextInfo(). As a result, this implementation provides both Ecma\Intl\Locale::getTextInfo() and Ecma\Intl\Locale::$textInfo, each of which return the same value.

getTimeZones() string[] | null

Returns a list of one or more time zone identifiers commonly used for this locale.

If the locale identifier does not contain a region subtag, this returns null. If it has a region subtag but the region does not have any commonly used time zone identifiers, this returns an empty array.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named timeZones, so most browsers implement this as Locale.timeZones. However, recent drafts of this proposal have changed the design to the method Locale.getTimeZones(). As a result, this implementation provides both Ecma\Intl\Locale::getTimeZones() and Ecma\Intl\Locale::$timeZones, each of which return the same value.

getWeekInfo() Ecma\Intl\Locale\WeekInfo

Returns an Ecma\Intl\Locale\WeekInfo object representing locale-specific information about the days of the week, for calendar purposes.

This method is defined as part of the Intl Locale Info Proposal, an ECMA-402 stage 3 draft. Originally, it was defined as a property accessor named weekInfo, so most browsers implement this as Locale.weekInfo. However, recent drafts of this proposal have changed the design to the method Locale.getWeekInfo(). As a result, this implementation provides both Ecma\Intl\Locale::getWeekInfo() and Ecma\Intl\Locale::$weekInfo, each of which return the same value.

jsonSerialize() object

Returns an object of Locale properties and their values, suitable for serializing to JSON.

maximize() Ecma\Intl\Locale

Returns a new instance of Ecma\Intl\Locale with all likely sub tags added according to the algorithm in Unicode Technical Standard #35.

For example:

  • “en” maximizes to “en-Latn-US”

  • “de” maximizes to “de-Latn-DE”

  • “sr” maximizes to “sr-Cyrl-RS”

  • “sh” maximizes to “sr-Latn-RS”

  • “zh” maximizes to “zh-Hans-CN”

minimize() Ecma\Intl\Locale

Returns a new instance of Ecma\Intl\Locale with sub tags removed according to the algorithm in Unicode Technical Standard #35.

For example:

  • “en-Latn-US” minimizes to “en”

  • “de-Latn-DE” minimizes to “de”

  • “sr-Cyrl-RS” minimizes to “sr”

  • “zh-Hant-TW” minimizes to “zh-TW”

toString() string

Returns a string representation of the full locale identifier.