/**
* Translate function, mimics the php gettext (alias _) function.
*
* The function checks if $jsSafe is true, then if $interpretBackslashes is true.
*
* @param string $string The string to translate
* @param boolean $jsSafe Make the result javascript safe
* @param boolean $interpretBackSlashes Interpret \t and \n
*
* @return string The translation of the string
*
* @since 1.7.0
*/
public function _($string, $jsSafe = false, $interpretBackSlashes = true)
{
// Detect empty string
if ($string == '') {
return '';
}
$key = strtoupper($string);
if (isset($this->strings[$key])) {
$string = $this->strings[$key];
// Store debug information
if ($this->debug) {
$value = Factory::getApplication()->get('debug_lang_const', true) ? $string : $key;
$string = '**' . $value . '**';
$caller = $this->getCallerInfo();
if (!\array_key_exists($key, $this->used)) {
$this->used[$key] = array();
}
$this->used[$key][] = $caller;
}
} else {
if ($this->debug) {
$info = [];
$info['trace'] = $this->getTrace();
$info['key'] = $key;
$info['string'] = $string;
if (!\array_key_exists($key, $this->orphans)) {
$this->orphans[$key] = array();
}
$this->orphans[$key][] = $info;
$string = '??' . $string . '??';
}
}
if ($jsSafe) {
// Javascript filter
$string = addslashes($string);
} elseif ($interpretBackSlashes) {
if (strpos($string, '\\') !== false) {
// Interpret \n and \t characters
$string = str_replace(array('\\\\', '\\t', '\\n'), array("\\", "\t", "\n"), $string);
}
}
return $string;
}