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|null $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)

Sets the current language.

loadInflection(string $language)

Loads inflection closure and rules.

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

Returns the plural form of a noun.

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

Format number according to locale or desired format.

array
parseKey(string $key)

Parses the language key.

bool
loadFromCache(string $language, string $file)

Loads language strings from cache.

loadStrings(string $language, string $file)

Loads all strings for the language.

array
getStrings(string $language, string $file)

Returns all strings from the chosen language file.

bool
has(string $key, string|null $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|null $language = null)

Returns the chosen string from the current language.

Details

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

Constructor.

Parameters

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

at line 89
__destruct()

Destructor.

at line 105
LoaderInterface getLoader()

Returns the language loader.

Return Value

LoaderInterface

at line 115
setCache(StoreInterface $cache)

Sets the cache.

Parameters

StoreInterface $cache Cache instance

at line 125
string getLanguage()

Gets the current language.

Return Value

string

at line 135
setLanguage(string $language)

Sets the current language.

Parameters

string $language Name of the language pack

at line 145
protected loadInflection(string $language)

Loads inflection closure and rules.

Parameters

string $language Name of the language pack

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

Returns the plural form of a noun.

Parameters

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

Return Value

string

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

Format number according to locale or desired format.

Parameters

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

Return Value

string

at line 210
protected array parseKey(string $key)

Parses the language key.

Parameters

string $key Language key

Return Value

array

at line 222
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 235
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 257
protected array getStrings(string $language, string $file)

Returns all strings from the chosen language file.

Parameters

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

Return Value

array

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

Returns TRUE if the string exists and FALSE if not.

Parameters

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

Return Value

bool

at line 294
protected string parsePluralizationTags(string $string)

Pluralize words between pluralization tags.

Parameters

string $string String to parse

Return Value

string

at line 308
protected string parseNumberTags(string $string)

Format numbers between number tags.

Parameters

string $string String to parse

Return Value

string

at line 322
protected string parseTags(string $string)

Parses tags.

Parameters

string $string String to parse

Return Value

string

at line 345
string get(string $key, array $vars = [], string|null $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|null $language Name of the language pack

Return Value

string