lithium\g11n\Locale::decompose()
Parses a locale into locale tags. This is the pendant to Locale::compose()
`.
Parameters
-
string
$locale
A locale in an arbitrary form (i.e.
'en_US'
or'EN-US'
).
Returns
arrayParsed language, script, territory and variant tags.
Source
public static function decompose($locale) {
$regex = '(?P<language>[a-z]{2,3})';
$regex .= '(?:[_-](?P<script>[a-z]{4}))?';
$regex .= '(?:[_-](?P<territory>[a-z]{2}))?';
$regex .= '(?:[_-](?P<variant>[a-z]{5,}))?';
if (!preg_match("/^{$regex}$/i", $locale, $matches)) {
throw new InvalidArgumentException("Locale `{$locale}` could not be parsed.");
}
return array_filter(array_intersect_key($matches, static::$_tags));
}