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.

Properties

static private array $locales

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

static private array $languages

List of language names

static private array $text_direction

Config for ltr/rtr of specific locales.

static private array $likely_subtags

Methods

static Injectable
create(array ...$args)

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

static Injectable
singleton(string $class = null)

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

static Config_ForClass
config()

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

mixed
stat(string $name) deprecated

Get inherited config value

mixed
uninherited(string $name)

Gets the uninherited value for the given config option

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

Update the config value for a given property

__construct()

No description

string
scriptDirection(string $locale = null)

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

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.

string
langFromLocale(string $locale)

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

array
getLocales()

Get all locale codes and names

array
getLanguages()

Get all language codes and names

string
localeName(string $locale)

Get name of locale

string
languageName(string $code)

Get language name for this language or locale code

array
getCountries()

Get all country codes and names

string
countryName(string $code)

Get name of country

string
countryFromLocale(string $locale)

Returns the country code / suffix on any locale

bool
validate(string $locale)

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

static 
reset()

Reset the local cache of this object

Details

static Injectable create(array ...$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'); $list = SiteTree::get();

Parameters

array ...$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()

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 {@link $locales}.

Parameters

string $locale

Return Value

bool

static reset()

Reset the local cache of this object