You are here

potx_test_8.html.twig in Translation template extractor 6.3

A test Twig template for potx.

File

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