class I18n

Internationalization class.

Properties

protected LoaderInterface $loader Language loader.
protected string $language Current language.
protected array $strings Loaded language strings.
protected array $inflections Loaded language inflections.
protected StoreInterface $cache Cache instance.
protected bool $rebuildCache Should we rebuild the cache?

Methods

__construct(LoaderInterface $loader, string $language, StoreInterface $cache = null)

Constructor.

__destruct()

Destructor.

getLoader()

Returns the language loader.

setCache(StoreInterface $cache)

Sets the cache.

string
getLanguage()

Gets the current language.

setLanguage(string $language = null)

Sets the current language.

loadInflection(string $language)

Loads inflection closure and rules.

string
pluralize(string $word, int $count = null, string $language = null)

Returns the plural form of a noun.

string
number(float $number, int $decimals = 0, string $decimalPoint = null, string $thousandsSeparator = null)

Format number according to locale or desired format.

bool
loadFromCache(string $language, string $file)

Loads language strings from cache.

loadStrings(string $language, string $file)

Loads all strings for the language.

array
parseKey(string $key)

Parses the language key.

string
getString(string $key, string $language = null)

Returns the language string.

bool
has(string $key, string $language = null)

Returns TRUE if the string exists and FALSE if not.

string
parsePluralizationTags(string $string)

Pluralize words between pluralization tags.

string
parseNumberTags(string $string)

Format numbers between number tags.

string
parseTags(string $string)

Parses tags.

string
get(string $key, array $vars = [], string $language = null)

Returns the chosen string from the current language.

Details

at line 78
__construct(LoaderInterface $loader, string $language, StoreInterface $cache = null)

Constructor.

Parameters

LoaderInterface $loader Loader instance
string $language Default language pack name
StoreInterface $cache Cache instance

at line 90
__destruct()

Destructor.

at line 106
LoaderInterface getLoader()

Returns the language loader.

Return Value

LoaderInterface

at line 116
setCache(StoreInterface $cache)

Sets the cache.

Parameters

StoreInterface $cache Cache instance

at line 126
string getLanguage()

Gets the current language.

Return Value

string

at line 136
setLanguage(string $language = null)

Sets the current language.

Parameters

string $language Name of the language pack

at line 146
protected loadInflection(string $language)

Loads inflection closure and rules.

Parameters

string $language Name of the language pack

at line 159
string pluralize(string $word, int $count = null, string $language = null)

Returns the plural form of a noun.

Parameters

string $word Noun to pluralize
int $count Number of nouns
string $language Language rules to use for pluralization

Return Value

string

at line 187
string number(float $number, int $decimals = 0, string $decimalPoint = null, string $thousandsSeparator = null)

Format number according to locale or desired format.

Parameters

float $number Number to format
int $decimals Number of decimals
string $decimalPoint Decimal point
string $thousandsSeparator Thousands separator

Return Value

string

at line 212
protected bool loadFromCache(string $language, string $file)

Loads language strings from cache.

Parameters

string $language Name of the language pack
string $file File from which we are loading the strings

Return Value

bool

at line 225
protected loadStrings(string $language, string $file)

Loads all strings for the language.

Parameters

string $language Name of the language pack
string $file File from which we are loading the strings

at line 246
protected array parseKey(string $key)

Parses the language key.

Parameters

string $key Language key

Return Value

array

at line 258
protected string getString(string $key, string $language = null)

Returns the language string.

Parameters

string $key Language key
string $language Name of the language pack

Return Value

string

at line 284
bool has(string $key, string $language = null)

Returns TRUE if the string exists and FALSE if not.

Parameters

string $key String to translate
string $language Name of the language pack

Return Value

bool

at line 309
protected string parsePluralizationTags(string $string)

Pluralize words between pluralization tags.

Parameters

string $string String to parse

Return Value

string

at line 323
protected string parseNumberTags(string $string)

Format numbers between number tags.

Parameters

string $string String to parse

Return Value

string

at line 337
protected string parseTags(string $string)

Parses tags.

Parameters

string $string String to parse

Return Value

string

at line 360
string get(string $key, array $vars = [], string $language = null)

Returns the chosen string from the current language.

Parameters

string $key String to translate
array $vars Array of values to replace in the translated text
string $language Name of the language pack

Return Value

string