PHP Класс lithium\g11n\Locale

In order to avoid unnecessary overhead all methods throughout the framework accepting a locale require it to be well-formed according to the structure laid out below. For assuring the correct format use Locale::canonicalize() once on the locale. However the methods within this class will also work with not-so-well-formed locales. They accept both underscores and hyphens as separators between and don't care about the case of the individual tags. The identifier used by Lithium is based in its structure upon Unicode's language identifier and is compliant to BCP 47. language[_Script][_TERRITORY][_VARIANT] - language The spoken language, here represented by an ISO 639-1 code, where not available ISO 639-3 and ISO 639-5 codes are allowed too) tag. The tag should be lower-cased and is required. - Script The tag should have its first character capitalized, all others lower-cased. The tag is optional. - TERRITORY A geographical area, here represented by an ISO 3166-1 code. Should be all upper-cased and is optional. - VARIANT Should be all upper-cased and is optional.
Наследование: extends lithium\core\StaticObject
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_tags array Properties for locale tags.

Открытые методы

Метод Описание
__callStatic ( string $method, array $params = [] ) : mixed Magic method enabling language, script, territory and variant methods to parse and retrieve individual tags from a locale.
canonicalize ( string $locale ) : string Returns a locale in its canonical form with tags formatted properly.
cascade ( string $locale ) : array Cascades a locale.
compose ( array $tags ) : string Composes a locale from locale tags. This is the pendant to Locale::decompose().
decompose ( string $locale ) : array Parses a locale into locale tags. This is the pendant to Locale::compose().
lookup ( array $locales, string $locale ) : string Searches an array of locales for the best match to a locale. The locale is iteratively simplified until either it matches one of the locales in the list or the locale can't be further simplified.
preferred ( object | array $request, array $available = null ) : string Determines the preferred locale from a request or array. Optionally negotiates the preferred locale with available locales.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.

Защищенные методы

Метод Описание
_preferredAction ( Request $request ) : array Detects preferred locales from an action request by looking at the 'Accept-Language' header as described by RFC 2616, section 14.4.
_preferredConsole ( Request $request ) : array Detects preferred locales from a console request by looking at certain environment variables. The environment variables may be present or not depending on your system. If multiple variables are present the following hierarchy is used: 'LANGUAGE', 'LC_ALL', 'LANG'.

Описание методов

__callStatic() публичный статический Метод

Locale::language('en_US'); // returns 'en' Locale::territory('en_US'); // returns 'US'
См. также: lithium\g11n\Locale::$_tags
См. также: lithium\g11n\Locale::decompose()
public static __callStatic ( string $method, array $params = [] ) : mixed
$method string
$params array
Результат mixed

_preferredAction() защищенный статический Метод

Detects preferred locales from an action request by looking at the 'Accept-Language' header as described by RFC 2616, section 14.4.
protected static _preferredAction ( Request $request ) : array
$request lithium\action\Request
Результат array Preferred locales in their canonical form (i.e. `'fr_CA'`).

_preferredConsole() защищенный статический Метод

The locales of the 'LC_ALL' and the 'LANG' are formatted according to the posix standard: language(_territory)(.encoding)(@modifier). Locales having such a format are automatically canonicalized and transformed into the Locale class' format.
protected static _preferredConsole ( Request $request ) : array
$request lithium\console\Request
Результат array Preferred locales in their canonical form (i.e. `'fr_CA'`).

canonicalize() публичный статический Метод

Returns a locale in its canonical form with tags formatted properly.
public static canonicalize ( string $locale ) : string
$locale string A locale in an arbitrary form (i.e. `'ZH-HANS-HK_REVISED'`).
Результат string A locale in its canonical form (i.e. `'zh_Hans_HK_REVISED'`).

cascade() публичный статический Метод

Usage: Locale::cascade('en_US'); returns array('en_US', 'en', 'root') Locale::cascade('zh_Hans_HK_REVISED'); returns array('zh_Hans_HK_REVISED', 'zh_Hans_HK', 'zh_Hans', 'zh', 'root')
public static cascade ( string $locale ) : array
$locale string A locale in an arbitrary form (i.e. `'en_US'` or `'EN-US'`).
Результат array Indexed array of locales (starting with the most specific one).

compose() публичный статический Метод

Composes a locale from locale tags. This is the pendant to Locale::decompose().
public static compose ( array $tags ) : string
$tags array An array as obtained from `Locale::decompose()`.
Результат string A locale with tags separated by underscores or `null` if none of the passed tags could be used to compose a locale.

decompose() публичный статический Метод

Parses a locale into locale tags. This is the pendant to Locale::compose().
public static decompose ( string $locale ) : array
$locale string A locale in an arbitrary form (i.e. `'en_US'` or `'EN-US'`).
Результат array Parsed language, script, territory and variant tags.

lookup() публичный статический Метод

This method partially implements the lookup matching scheme as described in RFC 4647, section 3.4 and thus does not strictly conform to the specification. Differences to specification: - No support for wildcards in the to-be-matched locales. - No support for locales with private subtags. - No support for a default return value. - Passed locales are required to be in canonical form (i.e. 'ja_JP').
public static lookup ( array $locales, string $locale ) : string
$locales array Locales to match against `$locale`.
$locale string A locale in its canonical form (i.e. `'zh_Hans_HK_REVISED'`).
Результат string The matched locale.

preferred() публичный статический Метод

Determines the preferred locale from a request or array. Optionally negotiates the preferred locale with available locales.
См. также: lithium\g11n\Locale::_preferredAction()
См. также: lithium\g11n\Locale::_preferredConsole()
См. также: lithium\g11n\Locale::lookup()
public static preferred ( object | array $request, array $available = null ) : string
$request object | array An action or console request object or an array of locales.
$available array A list of locales to negotiate the preferred locale with.
Результат string The preferred locale in its canonical form (i.e. `'fr_CA'`).

respondsTo() публичный статический Метод

Determines if a given method can be called.
public static respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
Результат boolean Returns `true` if the method can be called, `false` otherwise.

Описание свойств

$_tags защищенное статическое свойство

Properties for locale tags.
protected static array $_tags
Результат array