You are here

public function TranslatorPluginBase::escapeText in Translation Management Tool 8

Returns the escaped #text of a data item.

Parameters

array $data_item: A data item with a #text and optional #escape definitions.

Return value

string The text of the data item with translator-specific escape patterns applied.

Overrides TranslatorPluginInterface::escapeText

File

src/TranslatorPluginBase.php, line 131

Class

TranslatorPluginBase
Default controller class for service plugins.

Namespace

Drupal\tmgmt

Code

public function escapeText(array $data_item) {
  if (empty($data_item['#escape'])) {
    return $data_item['#text'];
  }
  $text = $data_item['#text'];
  $escape = $data_item['#escape'];

  // Sort them in reverse order based/ on the position and process them,
  // so that positions don't change.
  krsort($escape, SORT_NUMERIC);
  foreach ($escape as $position => $info) {
    $text = substr_replace($text, $this
      ->getEscapedString($info['string']), $position, strlen($info['string']));
  }
  return $text;
}