Back to Text class

Method passSprintf

private static bool
passSprintf
(mixed &$string, mixed $jsSafe = false, mixed $interpretBackSlashes = true, mixed $script = false)
Checks the string if it should be interpreted as sprintf and runs sprintf over it.
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
  • bool Whether the string be interpreted as sprintf
Since
  • 3.4.4
Class: Text
Project: Joomla

Method passSprintf - Source code

/**
 * Checks the string if it should be interpreted as sprintf and runs sprintf over it.
 *
 * @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  boolean  Whether the string be interpreted as sprintf
 *
 * @since   3.4.4
 */
private static function passSprintf(&$string, $jsSafe = false, $interpretBackSlashes = true, $script = false)
{
    // Check if string contains a comma
    if (strpos($string, ',') === false) {
        return false;
    }
    $lang = Factory::getLanguage();
    $string_parts = explode(',', $string);
    // Pass all parts through the Text translator
    foreach ($string_parts as $i => $str) {
        $string_parts[$i] = $lang->_($str, $jsSafe, $interpretBackSlashes);
    }
    $first_part = array_shift($string_parts);
    // Replace custom named placeholders with sprintf style placeholders
    $first_part = preg_replace('/\\[\\[%([0-9]+):[^\\]]*\\]\\]/', '%\\1$s', $first_part);
    // Check if string contains sprintf placeholders
    if (!preg_match('/%([0-9]+\\$)?s/', $first_part)) {
        return false;
    }
    $final_string = vsprintf($first_part, $string_parts);
    // Return false if string hasn't changed
    if ($first_part === $final_string) {
        return false;
    }
    $string = $final_string;
    if ($script) {
        foreach ($string_parts as $i => $str) {
            static::$strings[$str] = $string_parts[$i];
        }
    }
    return true;
}