diff options
Diffstat (limited to 'includes/bootstrap.inc')
-rw-r--r-- | includes/bootstrap.inc | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index b67139e14..758eb94c6 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -1431,15 +1431,7 @@ function drupal_unpack($obj, $field = 'data') { * A string containing the English string to translate. * @param $args * An associative array of replacements to make after translation. - * Occurrences in $string of any key in $args are replaced with the - * corresponding value, after sanitization. The sanitization function depends - * on the first character of the key: - * - !variable: Inserted as is. Use this for text that has already been - * sanitized. - * - @variable: Escaped to HTML using check_plain(). Use this for anything - * displayed on a page on the site. - * - %variable: Escaped as a placeholder for user-submitted content using - * drupal_placeholder(), which shows up as <em>emphasized</em> text. + * See format_string(). * @param $options * An associative array of additional options, with the following elements: * - 'langcode' (defaults to the current language): The language code to @@ -1485,26 +1477,50 @@ function t($string, array $args = array(), array $options = array()) { return $string; } else { - // Transform arguments before inserting them. - foreach ($args as $key => $value) { - switch ($key[0]) { - case '@': - // Escaped only. - $args[$key] = check_plain($value); - break; + return format_string($string, $args); + } +} - case '%': - default: - // Escaped and placeholder. - $args[$key] = drupal_placeholder($value); - break; +/** + * Replace placeholders with sanitized values in a string. + * + * @param $string + * A string containing placeholders. + * @param $args + * An associative array of replacements to make. Occurrences in $string of + * any key in $args are replaced with the corresponding value, after + * sanitization. The sanitization function depends on the first character of + * the key: + * - !variable: Inserted as is. Use this for text that has already been + * sanitized. + * - @variable: Escaped to HTML using check_plain(). Use this for anything + * displayed on a page on the site. + * - %variable: Escaped as a placeholder for user-submitted content using + * drupal_placeholder(), which shows up as <em>emphasized</em> text. + * + * @see t() + * @ingroup sanitization + */ +function format_string($string, array $args = array()) { + // Transform arguments before inserting them. + foreach ($args as $key => $value) { + switch ($key[0]) { + case '@': + // Escaped only. + $args[$key] = check_plain($value); + break; - case '!': - // Pass-through. - } + case '%': + default: + // Escaped and placeholder. + $args[$key] = drupal_placeholder($value); + break; + + case '!': + // Pass-through. } - return strtr($string, $args); } + return strtr($string, $args); } /** |