Back to Text class

Method _

public static string
_
(mixed $string, mixed $jsSafe = false, mixed $interpretBackSlashes = true, mixed $script = false)
Translates a string into the current language.
Parameters
  • string $string The string to translate.
  • mixed $jsSafe Boolean: Make the result javascript safe.
  • bool $interpretBackSlashes To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
  • bool $script To indicate that the string will be push in the javascript language store
Returns
  • string The translated string or the key if $script is true
Since
  • 1.7.0
Class: Text
Project: Joomla

Method _ - Source code

/**
 * Translates a string into the current language.
 *
 * Examples:
 * `<script>alert(Joomla.Text._('<?php echo Text::_("JDEFAULT", array("script"=>true)); ?>'));</script>`
 * will generate an alert message containing 'Default'
 * `<?php echo Text::_("JDEFAULT"); ?>` will generate a 'Default' string
 *
 * @param   string   $string                The string to translate.
 * @param   mixed    $jsSafe                Boolean: Make the result javascript safe.
 * @param   boolean  $interpretBackSlashes  To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
 * @param   boolean  $script                To indicate that the string will be push in the javascript language store
 *
 * @return  string  The translated string or the key if $script is true
 *
 * @since   1.7.0
 */
public static function _($string, $jsSafe = false, $interpretBackSlashes = true, $script = false)
{
    if (\is_array($jsSafe)) {
        if (\array_key_exists('interpretBackSlashes', $jsSafe)) {
            $interpretBackSlashes = (bool) $jsSafe['interpretBackSlashes'];
        }
        if (\array_key_exists('script', $jsSafe)) {
            $script = (bool) $jsSafe['script'];
        }
        $jsSafe = \array_key_exists('jsSafe', $jsSafe) ? (bool) $jsSafe['jsSafe'] : false;
    }
    if (self::passSprintf($string, $jsSafe, $interpretBackSlashes, $script)) {
        return $string;
    }
    $lang = Factory::getLanguage();
    if ($script) {
        static::$strings[$string] = $lang->_($string, $jsSafe, $interpretBackSlashes);
        return $string;
    }
    return $lang->_($string, $jsSafe, $interpretBackSlashes);
}