class ResourceBundle implements IteratorAggregate, Countable (View source)

Localized software products often require sets of data that are to be customized depending on current locale, e.g.: messages, labels, formatting patterns. ICU resource mechanism allows to define sets of resources that the application can load on locale basis, while accessing them in unified locale-independent fashion.

This class implements access to ICU resource data files. These files are binary data arrays which ICU uses to store the localized data. ICU resource bundle can hold simple resources and complex resources. Complex resources are containers which can be either integer-indexed or string-indexed (just like PHP arrays). Simple resources can be of the following types: string, integer, binary data field or integer array. ResourceBundle supports direct access to the data through array access pattern and iteration via foreach, as well as access via class methods. The result will be PHP value for simple resources and ResourceBundle object for complex ones. All resources are read-only.

Methods

__construct(string $locale, string $bundle, bool $fallback = true)

Create a resource bundle

static ResourceBundle|null
create(string $locale, string $bundle, bool $fallback = true)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Create a resource bundle

mixed
get(string|int $index, bool $fallback = true)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get data from the bundle

int
count()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get number of elements in the bundle

static array|false
getLocales(string $bundle)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get supported locales

int
getErrorCode()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get bundle's last error code.

string
getErrorMessage()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get bundle's last error message.

getIterator()

No description

Details

__construct(string $locale, string $bundle, bool $fallback = true)

Create a resource bundle

Creates a resource bundle.

Parameters

string $locale

Locale for which the resources should be loaded (locale name, e.g. en_CA).

string $bundle

The directory where the data is stored or the name of the .dat file.

bool $fallback

[optional]

Whether locale should match exactly or fallback to parent locale is allowed.

static ResourceBundle|null create(string $locale, string $bundle, bool $fallback = true)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Create a resource bundle

Parameters

string $locale

Locale for which the resources should be loaded (locale name, e.g. en_CA).

string $bundle

The directory where the data is stored or the name of the .dat file.

bool $fallback

[optional]

Whether locale should match exactly or fallback to parent locale is allowed.

Return Value

ResourceBundle|null

ResourceBundle object or null on error.

mixed get(string|int $index, bool $fallback = true)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get data from the bundle

Parameters

string|int $index

Data index, must be string or integer.

bool $fallback

Whether locale should match exactly or fallback to parent locale is allowed.

Return Value

mixed

the data located at the index or NULL on error. Strings, integers and binary data strings are returned as corresponding PHP types, integer array is returned as PHP array. Complex types are returned as ResourceBundle object.

int count()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get number of elements in the bundle

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

static array|false getLocales(string $bundle)

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get supported locales

Parameters

string $bundle

Path of ResourceBundle for which to get available locales, or empty string for default locales list.

Return Value

array|false

the list of locales supported by the bundle.

int getErrorCode()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get bundle's last error code.

Return Value

int

error code from last bundle object call.

string getErrorMessage()

(PHP >= 5.3.2, PECL intl >= 2.0.0)
Get bundle's last error message.

Return Value

string

error message from last bundle object's call.

Traversable getIterator()

Since: 8.0

No description

Return Value

Traversable

An instance of an object implementing Iterator or Traversable