You are here

function _potx_find_t_calls in Translation template extractor 6.2

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

Detect all occurances of t()-like calls.

These sequences are searched for: T_STRING("$function_name") + "(" + T_CONSTANT_ENCAPSED_STRING + ")" T_STRING("$function_name") + "(" + T_CONSTANT_ENCAPSED_STRING + ","

Parameters

$file: Name of file parsed.

$save_callback: Callback function used to save strings.

function_name: The name of the function to look for (could be 't', '$t', 'st' or any other t-like function).

$string_mode: String mode to use: POTX_STRING_INSTALLER, POTX_STRING_RUNTIME or POTX_STRING_BOTH.

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

File

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

Code

function _potx_find_t_calls($file, $save_callback, $function_name = 't', $string_mode = POTX_STRING_RUNTIME) {
  global $_potx_tokens, $_potx_lookup;

  // Lookup tokens by function name.
  if (isset($_potx_lookup[$function_name])) {
    foreach ($_potx_lookup[$function_name] as $ti) {
      list($ctok, $par, $mid, $rig) = array(
        $_potx_tokens[$ti],
        $_potx_tokens[$ti + 1],
        $_potx_tokens[$ti + 2],
        $_potx_tokens[$ti + 3],
      );
      list($type, $string, $line) = $ctok;
      if ($par == "(") {
        if (in_array($rig, array(
          ")",
          ",",
        )) && (is_array($mid) && $mid[0] == T_CONSTANT_ENCAPSED_STRING)) {
          $save_callback(_potx_format_quoted_string($mid[1]), $file, $line, $string_mode);
        }
        else {

          // $function_name() found, but inside is something which is not a string literal.
          _potx_marker_error($file, $line, $function_name, $ti, t('The first parameter to @function() should be a literal string. There should be no variables, concatenation, constants or other non-literal strings there.', array(
            '@function' => $function_name,
          )), 'http://drupal.org/node/322732');
        }
      }
    }
  }
}