\rex_i18n

Class for internationalization.

Summary

Methods
Properties
Constants
setLocale()
getLocale()
getLanguage()
addDirectory()
msg()
rawMsg()
msgInLocale()
rawMsgInLocale()
hasMsg()
hasMsgOrFallback()
addMsg()
getLocales()
translate()
translateArray()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

setLocale()

setLocale(string  $locale, bool  $phpSetLocale = true) : string

Switches the current locale.

Parameters

string $locale

The new locale

bool $phpSetLocale

When TRUE, php function setlocale() will be called

Returns

string —

The last locale

getLocale()

getLocale() : string

Returns the current locale, e.g. de_de.

Returns

string —

The current locale

getLanguage()

getLanguage() : string

Returns the current language, e.g. "de".

Returns

string —

The current language

addDirectory()

addDirectory(string  $dir) : mixed

Adds a directory with lang files.

Parameters

string $dir

Path to the directory

Returns

mixed —

msg()

msg(string  $key, string|int  ...$replacements) : string

Returns the translation htmlspecialchared for the given key.

Parameters

string $key

A Language-Key

string|int $replacements variadic

A arbritary number of strings used for interpolating within the resolved message

Returns

string —

Translation for the key

rawMsg()

rawMsg(string  $key, string|int  ...$replacements) : string

Returns the translation for the given key.

Parameters

string $key

A Language-Key

string|int $replacements variadic

A arbritary number of strings used for interpolating within the resolved message

Returns

string —

Translation for the key

msgInLocale()

msgInLocale(string  $key, string  $locale, string|int  ...$replacements) : string

Returns the translation htmlspecialchared for the given key and locale.

Parameters

string $key

A Language-Key

string $locale

A Locale

string|int $replacements variadic

A arbritary number of strings used for interpolating within the resolved message

Returns

string —

Translation for the key

rawMsgInLocale()

rawMsgInLocale(string  $key, string  $locale, string|int  ...$replacements) : string

Returns the translation for the given key and locale.

Parameters

string $key

A Language-Key

string $locale

A Locale

string|int $replacements variadic

A arbritary number of strings used for interpolating within the resolved message

Returns

string —

Translation for the key

hasMsg()

hasMsg(string  $key) : bool

Checks if there is a translation for the given key.

Parameters

string $key

Key

Returns

bool —

TRUE on success, else FALSE

hasMsgOrFallback()

hasMsgOrFallback(string  $key) : bool

Checks if there is a translation for the given key in current language or any fallback language.

Parameters

string $key

Key

Returns

bool —

TRUE on success, else FALSE

addMsg()

addMsg(string  $key, string  $message) : mixed

Adds a new translation to the catalogue.

Parameters

string $key

Key

string $message

Message for the key

Returns

mixed —

getLocales()

getLocales() : string[]

Returns the locales.

Returns

string[] —

Array of Locales

translate()

translate(string  $text, bool  $escape = true, callable  $i18nFunction = null) : string

Translates the $text, if it begins with 'translate:', else it returns $text.

Parameters

string $text

The text for translation

bool $escape

Flag whether the translated text should be escaped

callable $i18nFunction

Function that returns the translation for the i18n key

Throws

\InvalidArgumentException

Returns

string —

Translated text

translateArray()

translateArray(mixed  $array, bool  $escape = true, callable  $i18nFunction = null) : mixed

Translates all array elements.

Parameters

mixed $array

The Array of Strings for translation

bool $escape

Flag whether the translated text should be escaped

callable $i18nFunction

Function that returns the translation for the i18n key

Throws

\InvalidArgumentException

Returns

mixed —