You are here

function _potx_process_inline_templates in Translation template extractor 8

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

Process Twig inline templates inside PHP files. Drupal 8+.

The patterns searched for inline templates include: 1. '#template' => T_CONSTANT_ENCAPSED_STRING 2. ['#template'] = T_CONSTANT_ENCAPSED_STRING.

Parameters

string $file_name: Name of file parsed.

string $save_callback: Callback function used to save strings.

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

File

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

Code

function _potx_process_inline_templates($file_name, $save_callback) {
  global $_potx_tokens, $_potx_lookup;
  if (!isset($_potx_lookup["'#template'"])) {
    return;
  }
  foreach ($_potx_lookup["'#template'"] as $key => $ti) {

    // Check for pattern: '#template' => T_CONSTANT_ENCAPSED_STRING.
    if ($_potx_tokens[$ti + 1][0] == T_DOUBLE_ARROW && $_potx_tokens[$ti + 2][0] == T_CONSTANT_ENCAPSED_STRING) {
      $str = $_potx_tokens[$ti + 2][1];
      _potx_parse_twig_file($str, $file_name, $save_callback);
    }
    elseif ($_potx_tokens[$ti - 1] == '[' && $_potx_tokens[$ti + 1] == ']' && $_potx_tokens[$ti + 2] == '=' && $_potx_tokens[$ti + 3][0] == T_CONSTANT_ENCAPSED_STRING) {
      $str = $_potx_tokens[$ti + 3][1];
      _potx_parse_twig_file($str, $file_name, $save_callback);
    }
  }
}