I currently use formatPlural() to translate comment (not comments) and return its value to the Twig template.

\Drupal::translation()->formatPlural('', '1 comment', '@count comments'); 

Is there any way to use code similar to the following one in a Twig template to translate this word?

{{ 'comment'|trans }}
{{ 'comment'|t }}
{% trans %}comment{% endtrans %}
  • Why do you think you can't? There is no reason why that wouldn't work. The only thing is that you have to actually visit that page in a language different from english so they are tracked and you can add translations.
    – Berdir
    Jul 26, 2016 at 21:58
  • Also, you cannot use \Drupal::translation()->formatPlural('', '1 comment', '@count comments') to translate comment since, formatPlural() expects a number as first argument, and it would eventually translate 1 comment, not comment.
    – apaderno
    Jul 26, 2016 at 22:03
  • @Berdir I search for "comment" word in User interface translation section but seems does not exist any string on the filter result. Jul 26, 2016 at 22:13


Browse other questions tagged or ask your own question.