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.
파일 보기
프로젝트 열기: unionofrad/lithium
1 사용 예제들
보호된 프로퍼티들
공개 메소드들
메소드 |
설명 |
|
__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'
_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'`). |
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). |
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. |
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. |
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. |
Determines the preferred locale from a request or array. Optionally negotiates
the preferred locale with available locales.
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'`). |
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. |
프로퍼티 상세