secret
Last active

Potential Twig version of format_plural() and t()

  • Download Gist
gistfile1.twig
Twig
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{# Converts to format_plural() #}
{% format_plural %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endformat_plural %}
 
{# Converts to format_plural() #}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
 
{# Converts to t() #}
{% trans %}
Hello {{ name }}!
{% endtrans %}

What about this syntax?

{% format_plural apple_count %}
Hey {{ name }}, I have {{ apple_count }} apples.
{% singular %}
Hey {{ name }}, I have one apple.
{% endformat_plural %}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.