Commit 6e9bd504 authored by Jennifer Hodgdon's avatar Jennifer Hodgdon Committed by herom
Browse files

Issue #3037229 by jhodgdon: Extract template title meta-data from help topic Twig files

parent 45fad797
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1948,6 +1948,15 @@ function _potx_parse_js_string($string) {
 * Parse a Twig template for translatables. Drupal 8+.
 */
function _potx_parse_twig_file($code, $file, $save_callback) {
  // Extract meta tags, and save text in certain ones.
  $tags = get_meta_tags($file);
  $tags_to_save = ['help_topic:label'];
  foreach ($tags as $key => $content) {
    if (in_array($key, $tags_to_save)) {
      $save_callback(_potx_format_quoted_string('"' . trim($content) . '"'), POTX_CONTEXT_NONE, $file, 1);
    }
  }

  $twig_lexer = new Twig_Lexer(new Twig_Environment());

  try {
+3 −0
Original line number Diff line number Diff line
@@ -285,6 +285,9 @@ class PotxMockLanguageManager {
    $this->assertMsgId('Test string with @multiple_filters');
    $this->assertMsgId('Test string with %multiple_filters');

    $this->assertMsgID('Meta-data for a help topic title');
    $this->assertNoMsgID('Meta-data that should not be translated');

    $this->assertPotxErrors([
      'Concatenation error' => t('Uses of the t filter in Twig templates should start with a single literal string, and should not be chained.'),
    ]);
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@
 * A test Twig template for potx.
 */
#}
<meta name="help_topic:label" content="Meta-data for a help topic title"/>
<meta name="not_a_label" content="Meta-data that should not be translated"/>

<div id="test">
  {% if variable %}
    <span>{{ variable }}</span>