rex_i18n
in package
Class for internationalization.
Table of Contents
Methods
- addDirectory() : void
- Adds a directory with lang files.
- addMsg() : void
- Adds a new translation to the catalogue.
- getLanguage() : non-empty-string
- Returns the current language, e.g. "de".
- getLocale() : non-empty-string
- Returns the current locale, e.g. de_de.
- getLocales() : array<int, string>
- Returns the locales.
- hasMsg() : bool
- Checks if there is a translation for the given key.
- hasMsgOrFallback() : bool
- Checks if there is a translation for the given key in current language or any fallback language.
- msg() : non-empty-string
- Returns the translation htmlspecialchared for the given key.
- msgInLocale() : non-empty-string
- Returns the translation htmlspecialchared for the given key and locale.
- rawMsg() : non-empty-string
- Returns the translation for the given key.
- rawMsgInLocale() : non-empty-string
- Returns the translation for the given key and locale.
- setLocale() : string
- Switches the current locale.
- translate() : non-empty-string
- Translates the $text, if it begins with 'translate:', else it returns $text.
- translateArray() : mixed
- Translates all array elements.
Methods
addDirectory()
Adds a directory with lang files.
public
static addDirectory(string $dir) : void
Parameters
- $dir : string
-
Path to the directory
addMsg()
Adds a new translation to the catalogue.
public
static addMsg(string $key, non-empty-string $message) : void
Parameters
- $key : string
-
Key
- $message : non-empty-string
-
Message for the key
getLanguage()
Returns the current language, e.g. "de".
public
static getLanguage() : non-empty-string
Return values
non-empty-string —The current language
getLocale()
Returns the current locale, e.g. de_de.
public
static getLocale() : non-empty-string
Return values
non-empty-string —The current locale
getLocales()
Returns the locales.
public
static getLocales() : array<int, string>
Return values
array<int, string> —Array of Locales
hasMsg()
Checks if there is a translation for the given key.
public
static hasMsg(string $key) : bool
Parameters
- $key : string
-
Key
Return values
bool —TRUE on success, else FALSE
hasMsgOrFallback()
Checks if there is a translation for the given key in current language or any fallback language.
public
static hasMsgOrFallback(string $key) : bool
Parameters
- $key : string
-
Key
Return values
bool —TRUE on success, else FALSE
msg()
Returns the translation htmlspecialchared for the given key.
public
static msg(string $key, string|int ...$replacements) : non-empty-string
Parameters
- $key : string
-
A Language-Key
- $replacements : string|int
-
A arbritary number of strings used for interpolating within the resolved message
Tags
Return values
non-empty-string —Translation for the key
msgInLocale()
Returns the translation htmlspecialchared for the given key and locale.
public
static msgInLocale(string $key, string $locale, string|int ...$replacements) : non-empty-string
Parameters
- $key : string
-
A Language-Key
- $locale : string
-
A Locale
- $replacements : string|int
-
A arbritary number of strings used for interpolating within the resolved message
Tags
Return values
non-empty-string —Translation for the key
rawMsg()
Returns the translation for the given key.
public
static rawMsg(string $key, string|int ...$replacements) : non-empty-string
Parameters
- $key : string
-
A Language-Key
- $replacements : string|int
-
A arbritary number of strings used for interpolating within the resolved message
Tags
Return values
non-empty-string —Translation for the key
rawMsgInLocale()
Returns the translation for the given key and locale.
public
static rawMsgInLocale(string $key, string $locale, string|int ...$replacements) : non-empty-string
Parameters
- $key : string
-
A Language-Key
- $locale : string
-
A Locale
- $replacements : string|int
-
A arbritary number of strings used for interpolating within the resolved message
Return values
non-empty-string —Translation for the key
setLocale()
Switches the current locale.
public
static setLocale(string $locale[, bool $phpSetLocale = true ]) : string
Parameters
- $locale : string
-
The new locale
- $phpSetLocale : bool = true
-
When TRUE, php function setlocale() will be called
Return values
string —The last locale
translate()
Translates the $text, if it begins with 'translate:', else it returns $text.
public
static translate(string $text[, bool $escape = true ][, callable(string): string|null $i18nFunction = null ]) : non-empty-string
Parameters
- $text : string
-
The text for translation
- $escape : bool = true
-
Flag whether the translated text should be escaped
- $i18nFunction : callable(string): string|null = null
-
Function that returns the translation for the i18n key
Tags
Return values
non-empty-string —Translated text
translateArray()
Translates all array elements.
public
static translateArray(mixed $array[, bool $escape = true ][, callable $i18nFunction = null ]) : mixed
Parameters
- $array : mixed
-
The Array of Strings for translation
- $escape : bool = true
-
Flag whether the translated text should be escaped
- $i18nFunction : callable = null
-
Function that returns the translation for the i18n key