twig_theme_test.trans.html.twig

Same filename in other branches
  1. 8.9.x core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig
  2. 10 core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig
  3. 11.x core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig
{# Test trans tag with string argument. #}
<div>
  {% trans 'Hello sun.' %}
</div>

{# Test trans tag with string argument and context #}
<div>
  {% trans 'Hello sun.' with {'context': 'Lolspeak'} %}
</div>

{# Test trans filter. #}
<div>
  {{ 'Hello Earth.'|trans }}
</div>

{# Test trans tag with text content. #}
<div>
  {% trans %}
    Hello moon.
  {% endtrans %}
</div>

{# Test trans/plural tag where count = 1. #}
<div>
  {% set count = 1 %}
  {% trans %}
    Hello star.
  {% plural count %}
    Hello {{ count }} stars.
  {% endtrans %}
</div>

{# Test trans/plural tag where count = 2. #}
<div>
  {% set count = 2 %}
  {% trans %}
    Hello star.
  {% plural count %}
    Hello {{ count }} stars.
  {% endtrans %}
</div>

{# Test trans tag with different filters applied to tokens. #}
{% set string = '&"<>' %}
<div>
  {% trans %}
    Escaped: {{ string }}
  {% endtrans %}
</div>
<div>
  {% trans %}
    Placeholder: {{ string|placeholder }}
  {% endtrans %}
</div>

{# Test trans tag with complex tokens. #}
{% set token = {'name': 'complex token', 'numbers': '12345', 'bad_text': '&"<>' } %}
{% set count = token|length %}
<div>
  {% trans %}
    This {{ token.name }} has a length of: {{ count }}. It contains: {{ token.numbers|placeholder }} and {{ token.bad_text }}.
  {% endtrans %}
</div>

{# Test trans tag but with a context only msgid. #}
<div>
  {% trans %}
    I have context.
  {% endtrans %}
</div>

{# Test trans tag with context. #}
<div>
  {% trans with {'context': 'Lolspeak'} %}
    I have context.
  {% endtrans %}
</div>

{# Test trans tag with a specified language. #}
<div>
  {% trans with {'langcode': 'zz'} %}
    Hello new text.
  {% endtrans %}
</div>

{# Test trans tag with context and a specified language. #}
<div>
  {% trans with {'context': 'Lolspeak', 'langcode': 'zz'} %}
    Hello new text.
  {% endtrans %}
</div>

{# Tests that https://www.drupal.org/node/2489024 doesn't happen without twig debug. #}
<div>
  {% trans %}
    Number I never remember: ' . print(pi()) . '
  {% endtrans %}
</div>

File

core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig

View source
  1. {# Test trans tag with string argument. #}
  2. <div>
  3. {% trans 'Hello sun.' %}
  4. </div>
  5. {# Test trans tag with string argument and context #}
  6. <div>
  7. {% trans 'Hello sun.' with {'context': 'Lolspeak'} %}
  8. </div>
  9. {# Test trans filter. #}
  10. <div>
  11. {{ 'Hello Earth.'|trans }}
  12. </div>
  13. {# Test trans tag with text content. #}
  14. <div>
  15. {% trans %}
  16. Hello moon.
  17. {% endtrans %}
  18. </div>
  19. {# Test trans/plural tag where count = 1. #}
  20. <div>
  21. {% set count = 1 %}
  22. {% trans %}
  23. Hello star.
  24. {% plural count %}
  25. Hello {{ count }} stars.
  26. {% endtrans %}
  27. </div>
  28. {# Test trans/plural tag where count = 2. #}
  29. <div>
  30. {% set count = 2 %}
  31. {% trans %}
  32. Hello star.
  33. {% plural count %}
  34. Hello {{ count }} stars.
  35. {% endtrans %}
  36. </div>
  37. {# Test trans tag with different filters applied to tokens. #}
  38. {% set string = '&"<>' %}
  39. <div>
  40. {% trans %}
  41. Escaped: {{ string }}
  42. {% endtrans %}
  43. </div>
  44. <div>
  45. {% trans %}
  46. Placeholder: {{ string|placeholder }}
  47. {% endtrans %}
  48. </div>
  49. {# Test trans tag with complex tokens. #}
  50. {% set token = {'name': 'complex token', 'numbers': '12345', 'bad_text': '&"<>' } %}
  51. {% set count = token|length %}
  52. <div>
  53. {% trans %}
  54. This {{ token.name }} has a length of: {{ count }}. It contains: {{ token.numbers|placeholder }} and {{ token.bad_text }}.
  55. {% endtrans %}
  56. </div>
  57. {# Test trans tag but with a context only msgid. #}
  58. <div>
  59. {% trans %}
  60. I have context.
  61. {% endtrans %}
  62. </div>
  63. {# Test trans tag with context. #}
  64. <div>
  65. {% trans with {'context': 'Lolspeak'} %}
  66. I have context.
  67. {% endtrans %}
  68. </div>
  69. {# Test trans tag with a specified language. #}
  70. <div>
  71. {% trans with {'langcode': 'zz'} %}
  72. Hello new text.
  73. {% endtrans %}
  74. </div>
  75. {# Test trans tag with context and a specified language. #}
  76. <div>
  77. {% trans with {'context': 'Lolspeak', 'langcode': 'zz'} %}
  78. Hello new text.
  79. {% endtrans %}
  80. </div>
  81. {# Tests that https://www.drupal.org/node/2489024 doesn't happen without twig debug. #}
  82. <div>
  83. {% trans %}
  84. Number I never remember: ' . print(pi()) . '
  85. {% endtrans %}
  86. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.