class IntlLocales implements Locales, Resettable (View source)

Locale metadata

Language codes follow ISO 639-1 (2 letter), unless not present, in which case a locale will be encoded in ISO 639-3 (3 letter). See https://en.wikipedia.org/wiki/ISO_639

Country codes follow ISO 3166-1 alpha-2 (2 letter), unless not present, in which case a country code will be encoded in ISO 3166-1 alpha-3 (3 letter). See https://en.wikipedia.org/wiki/ISO_3166-1

Traits

A class that can be instantiated or replaced via DI

Provides extensions to this object to integrate it with standard config API methods.

Config options

locales array

An exhaustive list of possible locales (code => language and country)

languages array

List of language names

text_direction array

Config for ltr/rtr of specific locales.

likely_subtags array
countries array

Standard list of countries

cache_locales array

Cache of localised locales, keyed by locale localised in

cache_languages array

Cache of localised languages, keyed by locale localised in

cache_countries array

Cache of localised countries, keyed by locale localised in

Properties

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
stat(string $name) deprecated

Get inherited config value

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
$this
set_stat(string $name, mixed $value) deprecated

Update the config value for a given property

public
__construct()

No description

public
string
scriptDirection(string $locale = null)

Returns the script direction in format compatible with the HTML "dir" attribute.

public
string
localeFromLang(string $lang)

Provides you "likely locales" for a given "short" language code. This is a guess, as we can't disambiguate from e.g. "en" to "en_US" - it could also mean "en_UK". Based on the Unicode CLDR project.

public
string
langFromLocale(string $locale)

Returns the "short" language name from a locale, e.g. "en_US" would return "en".

public
array
getLocales()

Get all locale codes and names

public
array
getLanguages()

Get all language codes and names

public
string
localeName(string $locale)

Get name of locale

public
string
languageName(string $code)

Get language name for this language or locale code

public
array
getCountries()

Get all country codes and names

public
string
countryName(string $code)

Get name of country

public
string
countryFromLocale(string $locale)

Returns the country code / suffix on any locale

public
bool
validate(string $locale)

Validates a "long" locale format (e.g. "en_US") by checking it against $locales.

public static 
reset()

Reset the local cache of this object

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed stat(string $name) deprecated

deprecated 5.0 Use ->config()->get() instead

Get inherited config value

Parameters

string $name

Return Value

mixed

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

$this set_stat(string $name, mixed $value) deprecated

deprecated 5.0 Use ->config()->set() instead

Update the config value for a given property

Parameters

string $name
mixed $value

Return Value

$this

__construct()

No description

string scriptDirection(string $locale = null)

Returns the script direction in format compatible with the HTML "dir" attribute.

Parameters

string $locale

Optional locale incl. region (underscored)

Return Value

string

"rtl" or "ltr"

See also

http://www.w3.org/International/tutorials/bidi-xhtml/

string localeFromLang(string $lang)

Provides you "likely locales" for a given "short" language code. This is a guess, as we can't disambiguate from e.g. "en" to "en_US" - it could also mean "en_UK". Based on the Unicode CLDR project.

Parameters

string $lang

Short language code, e.g. "en"

Return Value

string

Long locale, e.g. "en_US"

See also

http://www.unicode.org/cldr/data/charts/supplemental/likely_subtags.html

string langFromLocale(string $locale)

Returns the "short" language name from a locale, e.g. "en_US" would return "en".

Parameters

string $locale

E.g. "en_US"

Return Value

string

Short language code, e.g. "en"

array getLocales()

Get all locale codes and names

Return Value

array

Map of locale code => name

array getLanguages()

Get all language codes and names

Return Value

array

Map of language code => name

string localeName(string $locale)

Get name of locale

Parameters

string $locale

Return Value

string

string languageName(string $code)

Get language name for this language or locale code

Parameters

string $code

Return Value

string

array getCountries()

Get all country codes and names

Return Value

array

Map of country code => name

string countryName(string $code)

Get name of country

Parameters

string $code

ISO 3166-1 country code

Return Value

string

string countryFromLocale(string $locale)

Returns the country code / suffix on any locale

Parameters

string $locale

E.g. "en_US"

Return Value

string

Country code, e.g. "us"

bool validate(string $locale)

Validates a "long" locale format (e.g. "en_US") by checking it against $locales.

Parameters

string $locale

Return Value

bool

static reset()

Reset the local cache of this object