You are here

function _potx_find_translation_annotations in Translation template extractor 7.2

Same name and namespace in other branches
  1. 8 potx.inc \_potx_find_translation_annotations()
  2. 6.3 potx.inc \_potx_find_translation_annotations()
  3. 7.3 potx.inc \_potx_find_translation_annotations()

Detect all occurances of @Translation annotations in doc comments.

Parameters

$file: Name of file parsed.

$save_callback: Callback function used to save strings.

1 call to _potx_find_translation_annotations()
_potx_process_file in ./potx.inc
Process a file and put extracted information to the given parameters.

File

./potx.inc, line 1851
Extraction API used by the web and command line interface.

Code

function _potx_find_translation_annotations($file, $save_callback) {
  global $_potx_tokens, $_potx_lookup;
  if (isset($_potx_lookup['T_DOC_COMMENT'])) {
    foreach ($_potx_lookup['T_DOC_COMMENT'] as $ti) {
      list($type, $string, $line) = $_potx_tokens[$ti];

      // Match for a possible empty string too, so we can signal that kind of
      // error in our standard way (from the save callback), instead of signaling
      // a generic error from here around syntax.
      preg_match_all('!=\\s*@Translation\\(\\s*"([^"]*)"(\\s*,\\s*context\\s*=\\s*("[^"]+"))?\\s*\\)!', $string, $found);
      if (isset($found) && is_array($found) && count($found[1])) {
        foreach ($found[1] as $index => $match) {
          $context = empty($found[3][$index]) ? POTX_CONTEXT_NONE : trim($found[3][$index], '"');
          $save_callback($match, $context, $file, $line);

          // Remove this annotation from the comment. This way if we have any
          // left after this foreach, we have bugos ones left and can use that
          // to signal an error.
          $string = str_replace($found[0][$index], '', $string);
        }
      }
      if (preg_match('!=\\s*@Translation!', $string) === 1) {

        // @Translation annotations still exist, so we have ones that did not
        // match the expected pattern.
        _potx_marker_error($file, $line, "@Translation", $ti, t('In @Translation, only one, non-empty static string is allowed in double quotes.'), 'https://drupal.org/node/1882526');
      }
    }
  }
}