You are here

potx_test_8.html.twig in Translation template extractor 8

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. {% set variableString = 'Variable string.'|t %}
  23. {% set variableString = 'Variable string with @placeholder.'|t({'@placeholder': 'placeholder'}) %}
  24. {% set variableString = 'Variable string with @translatedPlaceholder.'|t({'@translatedPlaceholder': 'translatedPlaceholder'|t}) %}
  25. {# Test include string with t filter. #}
  26. {% include '@testnamespace/components/a-component-template.twig' with {
  27. 'text': 'An include component template'|t,
  28. }
  29. %}
  30. {# Test trans tag with string argument. #}
  31. <div>
  32. {% trans 'Hello sun.' %}
  33. </div>
  34. {# Test trans tag with string argument and context #}
  35. <div>
  36. {% trans 'Hello sun, with context.' with {'context': 'Lolspeak'} %}
  37. </div>
  38. {# Test trans filter. #}
  39. <div>
  40. {{ 'Hello Earth.'|trans }}
  41. </div>
  42. {# Test trans tag with text content. #}
  43. <div>
  44. {% trans %}
  45. Hello moon.
  46. {% endtrans %}
  47. </div>
  48. {# Test trans/plural tag where count = 1. #}
  49. <div>
  50. {% set count = 1 %}
  51. {% trans %}
  52. Hello star.
  53. {% plural count %}
  54. Hello {{ count }} stars.
  55. {% endtrans %}
  56. </div>
  57. {# Test trans/plural tag where count = 2. #}
  58. <div>
  59. {% set count = 2 %}
  60. {% trans %}
  61. Hello star.
  62. {% plural count %}
  63. Hello {{ count }} stars.
  64. {% endtrans %}
  65. </div>
  66. {# Test trans tag with different filters applied to tokens. #}
  67. {% set string = '&"<>' %}
  68. <div>
  69. {% trans %}
  70. Escaped: {{ string }}
  71. {% endtrans %}
  72. </div>
  73. <div>
  74. {% trans %}
  75. Placeholder: {{ string|placeholder }}
  76. {% endtrans %}
  77. </div>
  78. {# Test trans tag with complex tokens. #}
  79. {% set node = {'type': 'complex token', 'numbers': '12345', 'bad_text': '&"<>' } %}
  80. {% set author = {'name': 'foo'} %}
  81. {% set count = token|length %}
  82. <div>
  83. {% trans %}
  84. This {{ node.type }} is submitted by {{ author.name }}, and has a length of: {{ count }}. It contains: {{ node.numbers|placeholder }} and {{ node.bad_text }}.
  85. {% endtrans %}
  86. </div>
  87. {# Test trans tag with context. #}
  88. <div>
  89. {% trans with {'context': 'Lolspeak'} %}
  90. I have context.
  91. {% endtrans %}
  92. </div>
  93. {# Test trans tag with a parameter that isn't 'context'. #}
  94. <div>
  95. {% trans with {'langcode': 'zz'} %}
  96. I have no context.
  97. {% endtrans %}
  98. </div>
  99. {# Test trans tag with context and another parameter. #}
  100. <div>
  101. {% trans with {'context': 'Lolspeak', 'langcode': 'zz'} %}
  102. I have context and another parameter.
  103. {% endtrans %}
  104. </div>
  105. {# Test a multiline trans tag. #}
  106. <div>
  107. {% trans %}
  108. A multiline
  109. trans block.
  110. {% endtrans %}
  111. </div>
  112. <div>
  113. {% trans %}
  114. Test string with {{ extra_filter|abs }}
  115. {% endtrans %}
  116. </div>
  117. <div>
  118. {% trans %}
  119. Test string with {{ multiple_filters|abs|placeholder }}
  120. {% endtrans %}
  121. </div>
  122. <div>
  123. {% trans %}
  124. Test string with {{ multiple_filters|placeholder|abs }}
  125. {% endtrans %}
  126. </div>