function i18n_string_format in Internationalization 7
Format the resulting translation or the default string applying callbacks
Parameters
$string: Text string.
$options: Array of options for string formatting:
- 'format', text format to apply to the string, defaults to none.
- 'sanitize', whether to apply the text format, defaults to TRUE.
- 'cache', text format parameter.
- 'langcode', text format parameter, defaults to current page language.
- 'allowed_tags', allowed HTML tags when format is I18N_STRING_FILTER_XSS
3 calls to i18n_string_format()
- i18n_string_object::format_translation in i18n_string/
i18n_string.inc - Format the resulting translation or the default string applying callbacks
- i18n_string_translate in i18n_string/
i18n_string.module - Get translation for user defined string.
- i18n_string_translate_list in i18n_string/
i18n_string.module - Translation for list of options
File
- i18n_string/
i18n_string.module, line 691 - Internationalization (i18n) package - translatable strings.
Code
function i18n_string_format($string, $options = array()) {
$options += array(
'langcode' => i18n_langcode(),
'format' => FALSE,
'sanitize' => TRUE,
'cache' => FALSE,
);
// Apply format and callback
if ($string) {
if ($options['sanitize']) {
if ($options['format']) {
// Handle special format values (xss, xss_admin)
switch ($options['format']) {
case I18N_STRING_FILTER_XSS:
$string = !empty($options['allowed_tags']) ? filter_xss($string, $options['allowed_tags']) : filter_xss($string);
break;
case I18N_STRING_FILTER_XSS_ADMIN:
$string = filter_xss_admin($string);
break;
default:
$string = check_markup($string, $options['format'], $options['langcode'], $options['cache']);
}
}
else {
$string = check_plain($string);
}
}
if (isset($options['callback'])) {
$string = call_user_func($options['callback'], $string);
}
}
// Finally, apply prefix and suffix
$options += array(
'prefix' => '',
'suffix' => '',
);
return $options['prefix'] . $string . $options['suffix'];
}