You are here

function _potx_find_format_plural_calls in Translation template extractor 5

Same name and namespace in other branches
  1. 8 potx.inc \_potx_find_format_plural_calls()
  2. 5.2 potx.inc \_potx_find_format_plural_calls()
  3. 6.3 potx.inc \_potx_find_format_plural_calls()
  4. 6 potx.inc \_potx_find_format_plural_calls()
  5. 6.2 potx.inc \_potx_find_format_plural_calls()
  6. 7.3 potx.inc \_potx_find_format_plural_calls()
  7. 7 potx.inc \_potx_find_format_plural_calls()
  8. 7.2 potx.inc \_potx_find_format_plural_calls()

Detect all occurances of format_plural calls.

These sequences are searched for: T_STRING("format_plural") + "(" + ..anything (might be more tokens).. + "," + T_CONSTANT_ENCAPSED_STRING + "," + T_CONSTANT_ENCAPSED_STRING + parenthesis (or comma allowed in Drupal 6)

Parameters

$file: Name of file parsed.

$save_callback: Callback function used to save strings.

$api_version: Drupal API version to work with.

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

File

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

Code

function _potx_find_format_plural_calls($file, $save_callback, $api_version = POTX_API_6) {
  global $_potx_tokens, $_potx_lookup;
  if (isset($_potx_lookup['format_plural'])) {
    foreach ($_potx_lookup['format_plural'] as $ti) {
      list($ctok, $par1) = array(
        $_potx_tokens[$ti],
        $_potx_tokens[$ti + 1],
      );
      list($type, $string, $line) = $ctok;
      if ($par1 == "(") {

        // Eat up everything that is used as the first parameter
        $tn = $ti + 2;
        $depth = 0;
        while (!($_potx_tokens[$tn] == "," && $depth == 0)) {
          if ($_potx_tokens[$tn] == "(") {
            $depth++;
          }
          elseif ($_potx_tokens[$tn] == ")") {
            $depth--;
          }
          $tn++;
        }

        // Get further parameters
        list($comma1, $singular, $comma2, $plural, $par2) = array(
          $_potx_tokens[$tn],
          $_potx_tokens[$tn + 1],
          $_potx_tokens[$tn + 2],
          $_potx_tokens[$tn + 3],
          $_potx_tokens[$tn + 4],
        );
        if ($comma2 == ',' && ($par2 == ')' || $par2 == ',' && $api_version > POTX_API_5) && (is_array($singular) && $singular[0] == T_CONSTANT_ENCAPSED_STRING) && (is_array($plural) && $plural[0] == T_CONSTANT_ENCAPSED_STRING)) {
          $save_callback(_potx_format_quoted_string($singular[1]) . "\0" . _potx_format_quoted_string($plural[1]), $file, $line);
        }
        else {

          // format_plural() found, but the parameters are not correct.
          _potx_marker_error($file, $line, "format_plural", $ti);
        }
      }
    }
  }
}