You are here

potx_test_8.html.twig in Translation template extractor 7.3

A test Twig template for potx.

File

tests/potx_test_8.html.twig
View source
  1. ---
  2. label: 'Meta-data for a help topic title'
  3. not_a_label: 'Meta-data that should not be translated'
  4. ---
  5. {#
  6. /**
  7. * @file
  8. * A test Twig template for potx.
  9. */
  10. #}
  11. <div id="test">
  12. {% if variable %}
  13. <span>{{ variable }}</span>
  14. {{ 'This is a translated string.'|t }}
  15. {% endif %}
  16. </div>
  17. <div>{{ 'Here\'s a string with an escaped quote.'|t }}</div>
  18. <div>{{ "A double-quoted string"|t }}</div>
  19. <div>{{ "Here's a double-quoted \"and escaped\" string."|t }}</div>
  20. {{ 'This is a concatenated string ' . 'that should not be picked up.'|t }}
  21. {{ 'This is an untranslated string.' }}
  22. {# Test trans tag with string argument. #}
  23. <div>
  24. {% trans 'Hello sun.' %}
  25. </div>
  26. {# Test trans tag with string argument and context #}
  27. <div>
  28. {% trans 'Hello sun, with context.' with {'context': 'Lolspeak'} %}
  29. </div>
  30. {# Test trans filter. #}
  31. <div>
  32. {{ 'Hello Earth.'|trans }}
  33. </div>
  34. {# Test trans tag with text content. #}
  35. <div>
  36. {% trans %}
  37. Hello moon.
  38. {% endtrans %}
  39. </div>
  40. {# Test trans/plural tag where count = 1. #}
  41. <div>
  42. {% set count = 1 %}
  43. {% trans %}
  44. Hello star.
  45. {% plural count %}
  46. Hello {{ count }} stars.
  47. {% endtrans %}
  48. </div>
  49. {# Test trans/plural tag where count = 2. #}
  50. <div>
  51. {% set count = 2 %}
  52. {% trans %}
  53. Hello star.
  54. {% plural count %}
  55. Hello {{ count }} stars.
  56. {% endtrans %}
  57. </div>
  58. {# Test trans tag with different filters applied to tokens. #}
  59. {% set string = '&"<>' %}
  60. <div>
  61. {% trans %}
  62. Escaped: {{ string }}
  63. {% endtrans %}
  64. </div>
  65. <div>
  66. {% trans %}
  67. Placeholder: {{ string|placeholder }}
  68. {% endtrans %}
  69. </div>
  70. {# Test trans tag with complex tokens. #}
  71. {% set node = {'type': 'complex token', 'numbers': '12345', 'bad_text': '&"<>' } %}
  72. {% set author = {'name': 'foo'} %}
  73. {% set count = token|length %}
  74. <div>
  75. {% trans %}
  76. This {{ node.type }} is submitted by {{ author.name }}, and has a length of: {{ count }}. It contains: {{ node.numbers|placeholder }} and {{ node.bad_text }}.
  77. {% endtrans %}
  78. </div>
  79. {# Test trans tag with context. #}
  80. <div>
  81. {% trans with {'context': 'Lolspeak'} %}
  82. I have context.
  83. {% endtrans %}
  84. </div>
  85. {# Test trans tag with a parameter that isn't 'context'. #}
  86. <div>
  87. {% trans with {'langcode': 'zz'} %}
  88. I have no context.
  89. {% endtrans %}
  90. </div>
  91. {# Test trans tag with context and another parameter. #}
  92. <div>
  93. {% trans with {'context': 'Lolspeak', 'langcode': 'zz'} %}
  94. I have context and another parameter.
  95. {% endtrans %}
  96. </div>
  97. {# Test a multiline trans tag. #}
  98. <div>
  99. {% trans %}
  100. A multiline
  101. trans block.
  102. {% endtrans %}
  103. </div>
  104. <div>
  105. {% trans %}
  106. Test string with {{ extra_filter|abs }}
  107. {% endtrans %}
  108. </div>
  109. <div>
  110. {% trans %}
  111. Test string with {{ multiple_filters|abs|placeholder }}
  112. {% endtrans %}
  113. </div>
  114. <div>
  115. {% trans %}
  116. Test string with {{ multiple_filters|placeholder|abs }}
  117. {% endtrans %}
  118. </div>