You are here

function _potx_process_twig_t_filter in Translation template extractor 8

Parses a single |t filter, and extracts the translatable string.

A |t filter can have the following formats: 1. {% 'string'|t %} 1. {% 'string @placeholder'|t({'@placeholder': 'placeholder' %}

Parameters

Twig_TokenStream $stream: The twig token stream.

1 call to _potx_process_twig_t_filter()
_potx_parse_twig_file in ./potx.inc
Parse a Twig template for translatables. Drupal 8+.

File

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

Code

function _potx_process_twig_t_filter(Twig_Token $token, Twig_TokenStream $stream, $file, $save_callback) {
  if ($token
    ->test(Twig_Token::STRING_TYPE)) {
    $string = $token
      ->getValue();
    $line = $token
      ->getLine();
    $has_t = FALSE;
    if ($stream
      ->test(Twig_Token::PUNCTUATION_TYPE, '|')) {
      $token = $stream
        ->next();
      if ($stream
        ->test([
        't',
        'trans',
      ])) {
        $has_t = TRUE;
        $token = $stream
          ->next();

        // This is t.
      }
    }
    if ($has_t) {
      $save_callback(_potx_format_quoted_string('"' . trim($string) . '"'), POTX_CONTEXT_NONE, $file, $line);
    }
  }
}