Skip to content

Instantly share code, notes, and snippets.

@joelpittet
Last active December 14, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joelpittet/742f9ee5c9c6ac41c39e to your computer and use it in GitHub Desktop.
Save joelpittet/742f9ee5c9c6ac41c39e to your computer and use it in GitHub Desktop.
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
Copy link

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