function lingotek_filter_placeholders in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.7 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
Return value
string the original input plus any additional reference tags to be ignored.
2 calls to lingotek_filter_placeholders()
- LingotekConfigChunk::documentLingotekXML in lib/
Drupal/ lingotek/ LingotekConfigChunk.php - Gets the contents of this item formatted as XML to be sent to Lingotek.
- lingotek_xml_fields in ./
lingotek.util.inc
File
- ./
lingotek.util.inc, line 1396 - 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 !,@,%
}
$replacement = '<drupalvar>${1}</drupalvar>';
foreach ($patterns as $p) {
$segment_text = preg_replace($p, $replacement, $segment_text);
}
return $segment_text;
}