function lingotek_filter_placeholders in Lingotek Translation 7.7
Same name and namespace in other branches
- 7.4 lingotek.util.inc \lingotek_filter_placeholders()
- 7.5 lingotek.util.inc \lingotek_filter_placeholders()
- 7.6 lingotek.util.inc \lingotek_filter_placeholders()
Wrap placeholder tags in specific tags that will be ignored by Lingotek
Parameters
$segment_text: a string containing the segment to be translated
$protect_vars: TRUE if filter should protect variables using !, @, or %, FALSE otherwise
Return value
string the original input plus any additional reference tags to be ignored.
3 calls to lingotek_filter_placeholders()
- LingotekConfigSet::documentLingotekXML in lib/
Drupal/ lingotek/ LingotekConfigSet.php - Gets the contents of this item formatted as XML to be sent to Lingotek.
- lingotek_attach_xml in ./
lingotek.module - lingotek_xml_fields in ./
lingotek.util.inc
File
- ./
lingotek.util.inc, line 2076 - Utility functions.
Code
function lingotek_filter_placeholders($segment_text, $protect_vars = FALSE) {
// NOTE: This regex is only a generalization of the variable names possible using
// the t-function's variable interpolation. This finds all sets of word
// characters (A-Z, a-z, - or _) that begin with either !, @, or %, that do not
// fall between angle brackets (which would indicate being on the inside
// of an HTML tag). It also protects everything inside square brackets
// that do not fall inside angle brackets.
$patterns = array(
'/(\\[[!@%\\w:=\\/\\&\\;\\s_-]+\\]\\s*)(?![^<]*\\>)/',
);
if ($protect_vars) {
$patterns[] = '/([!@%][\\w_-]+\\s*)(?![^<]*\\>)/';
// wrap everything beginning with !,@,%
}
// Provide the ability to modify the pattern for searching variables.
drupal_alter('lingotek_protect_variables', $patterns, $protect_vars);
$replacement = '<drupalvar>${1}</drupalvar>';
foreach ($patterns as $p) {
$segment_text = preg_replace($p, $replacement, $segment_text);
}
return $segment_text;
}