You are here

function _potx_find_t_calls in Translation template extractor 8

Same name and namespace in other branches
  1. 5.2 potx.inc \_potx_find_t_calls()
  2. 5 potx.inc \_potx_find_t_calls()
  3. 6.3 potx.inc \_potx_find_t_calls()
  4. 6 potx.inc \_potx_find_t_calls()
  5. 6.2 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

string $file: Name of file parsed.

string $save_callback: Callback function used to save strings.

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

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

1 call to _potx_find_t_calls()
_potx_parse_php_file in ./potx.inc
Parse a PHP file for translatables.

File

./potx.inc, line 999
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($prev, $ctok, $par, $mid, $rig) = [
        $_potx_tokens[$ti - 1],
        $_potx_tokens[$ti],
        $_potx_tokens[$ti + 1],
        $_potx_tokens[$ti + 2],
        $_potx_tokens[$ti + 3],
      ];
      list($type, $string, $line) = $ctok;
      if (is_array($prev) && $prev[0] == T_FUNCTION) {
        continue;
      }
      if ($function_name == 'debug' && is_array($prev) && $prev[0] != T_OBJECT_OPERATOR) {
        continue;
      }
      if ($par == "(") {
        if (in_array($rig, [
          ")",
          ",",
        ]) && (is_array($mid) && $mid[0] == T_CONSTANT_ENCAPSED_STRING)) {

          // This function is only used for context-less call types.
          $save_callback(_potx_format_quoted_string($mid[1]), POTX_CONTEXT_NONE, $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.', [
            '@function' => $function_name,
          ]), 'http://drupal.org/node/322732');
        }
      }
    }
  }
}