Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function LocaleSource::getData

Returns an array with the data structured for translation.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item: The job item entity.

Overrides SourcePluginInterface::getData

See also

JobItem::getData()

File

sources/locale/src/Plugin/tmgmt/Source/LocaleSource.php, line 175

Class

LocaleSource
Translation Source plugin for locale strings.

Namespace

Drupal\tmgmt_locale\Plugin\tmgmt\Source

Code

public function getData(JobItemInterface $job_item) {
  $locale_object = $this
    ->getLocaleObject($job_item);
  if (empty($locale_object)) {
    throw new TMGMTException(t('Unable to load %language translation for the locale %id', array(
      '%language' => $job_item
        ->getJob()
        ->getSourceLanguage()
        ->getName(),
      '%id' => $job_item
        ->getItemId(),
    )));
  }
  if ($locale_object->origin == 'source') {
    $text = $locale_object->source;
  }
  else {
    $text = $locale_object->translation;
  }

  // Identify placeholders that need to be escaped. Assume that placeholders
  // consist of alphanumeric characters and _,- only and are delimited by
  // non-alphanumeric characters. There are cases that don't match, for
  // example appended SI units like "@valuems", there only @value is the
  // actual placeholder.
  $escape = array();
  if (preg_match_all('/([@!%][a-zA-Z0-9_-]+)/', $text, $matches, PREG_OFFSET_CAPTURE)) {
    foreach ($matches[0] as $match) {
      $escape[$match[1]]['string'] = $match[0];
    }
  }
  $structure['singular'] = array(
    '#label' => t('Singular'),
    '#text' => (string) $text,
    '#translate' => TRUE,
    '#escape' => $escape,
  );
  return $structure;
}