|
The Locale classIntroductionA "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU (and many vendors of Unix-like operating systems, the Mac, Java, and so forth) use. Locales are identified using RFC 4646 language tags (which use hyphen, not underscore) in addition to the more traditional underscore-using identifiers. Unless otherwise noted the functions in this class are tolerant of both formats. Examples of identifiers include:
The Locale class (and related procedural functions) are used to interact with locale identifiers--to verify that an ID is well-formed, valid, etc. The extensions used by CLDR in UAX #35 (and inherited by ICU) are valid and used wherever they would be in ICU normally. Locales cannot be instantiated as objects. All of the functions/methods provided are static. The null or empty string obtains the "root" locale. The "root" locale is equivalent to "en_US_POSIX" in CLDR. Language tags (and thus locale identifiers) are case insensitive. There exists a canonicalization function to make case match the specification. Class synopsis
Locale
/* Constants */
public
const
int
Locale::ACTUAL_LOCALE;
public
const
int
Locale::VALID_LOCALE;
public
const
null
Locale::DEFAULT_LOCALE = null;
public
const
string
Locale::LANG_TAG;
public
const
string
Locale::EXTLANG_TAG;
public
const
string
Locale::SCRIPT_TAG;
public
const
string
Locale::REGION_TAG;
public
const
string
Locale::VARIANT_TAG;
public
const
string
Locale::GRANDFATHERED_LANG_TAG;
public
const
string
Locale::PRIVATE_TAG;
/* Methods */
public static stringfalse acceptFromHttp(string
$header )public static stringnull canonicalize(string
$locale )public static stringfalse composeLocale(array
$subtags )public static boolnull filterMatches(string
$languageTag , string $locale , bool $canonicalize = false )public static arraynull getAllVariants(string
$locale )public static string getDefault()
public static stringfalse getDisplayLanguage(string
$locale , stringnull $displayLocale = null )public static stringfalse getDisplayName(string
$locale , stringnull $displayLocale = null )public static stringfalse getDisplayRegion(string
$locale , stringnull $displayLocale = null )public static stringfalse getDisplayScript(string
$locale , stringnull $displayLocale = null )public static stringfalse getDisplayVariant(string
$locale , stringnull $displayLocale = null )public static arrayfalsenull getKeywords(string
$locale )public static stringnull getPrimaryLanguage(string
$locale )public static stringnull getRegion(string
$locale )public static stringnull getScript(string
$locale )public static stringnull lookup(
array $languageTag ,string $locale ,bool $canonicalize = false ,stringnull $defaultLocale = null ) public static arraynull parseLocale(string
$locale )public static bool setDefault(string
$locale )Predefined Constants
These constants describe the choice of the locale for the getLocale method of different classes.
Locale SubtagsThese constants define how the Locales are parsed or composed. They should be used as keys in the argument array to locale_compose and are returned from locale_parse as keys of the returned associative array.
|