Create a gist now

Instantly share code, notes, and snippets.

Potential Twig version of format_plural() and t()
{# 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 %}
@steveoliver

What about this syntax?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment