Translator
Click here if you want to read this article for the latest version.
Piwik\Translation\
Translator
Translates messages.
Methods
The class defines the following methods:
__construct()clean()— Clean a string that may contain HTML special chars, single/double quotes, HTML entities, leading/trailing whitespacetranslate()— Returns an internationalized string using a translation ID.getCurrentLanguage()setCurrentLanguage()getDefaultLanguage()getJavascriptTranslations()— Generate javascript translations arrayaddDirectory()— Add a directory containing translations.reset()— Should be used by tests only, and this method should eventually be removed.findTranslationKeyForTranslation()getAllTranslations()— Returns all the translation messages loaded.
__construct()
Signature
It accepts the following parameter(s):
$loader(Piwik\Translation\Loader\LoaderInterface) —$directories(array) —
clean()
Clean a string that may contain HTML special chars, single/double quotes, HTML entities, leading/trailing whitespace
Signature
It accepts the following parameter(s):
$s(string) —
It returns a
stringvalue.
translate()
Returns an internationalized string using a translation ID. If a translation cannot be found for the ID, the ID is returned.
Signature
It accepts the following parameter(s):
$translationId(string) — Translation ID, eg,General_Date.$args(array|string|int) —sprintfarguments to be applied to the internationalized string.$language(string|null) — Optionally force the language.
Returns:
string— The translated string or$translationId.
getCurrentLanguage()
Signature
- It returns a
stringvalue.
setCurrentLanguage()
Signature
It accepts the following parameter(s):
$language(string) —
It does not return anything or a mixed result.
getDefaultLanguage()
Signature
- Returns:
string— The default configured language.
getJavascriptTranslations()
Generate javascript translations array
Signature
- It does not return anything or a mixed result.
addDirectory()
Add a directory containing translations.
Signature
It accepts the following parameter(s):
$directory(string) —
It does not return anything or a mixed result.
reset()
Should be used by tests only, and this method should eventually be removed.
Signature
- It does not return anything or a mixed result.
findTranslationKeyForTranslation()
Signature
It accepts the following parameter(s):
$translation(string) —
Returns:
null|string—
getAllTranslations()
Returns all the translation messages loaded.
Signature
- It returns a
arrayvalue.