We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

{% trans %} tag for Volt: Multilanguage support.

Drupal 8 have in Twig Template:

{% trans %}
  Submitted by {{ author.username }} on {{ node.created }}
{% endtrans %}

I find it very useful, but not yet define as i18n my website. I am interested in performance much.

Something similar to Volt? it's a good idea?.



145.0k
Accepted
answer

Just use phalcon translation with this function in volt:

            $volt->getCompiler()->addFunction('_', function($resolvedArgs) {
                return '$t->_(' . $resolvedArgs . ')';
            });

Is good practice translate strings in the view? What do you think?

Just use phalcon translation with this function in volt:

           $volt->getCompiler()->addFunction('_', function($resolvedArgs) {
               return '$t->_(' . $resolvedArgs . ')';
           });

Well - if they are gonna be used in many places then it's great idea. If not it's still good because you can have all strings in one file, and you don't have to look for something, just remember the key.

You can not deploy {% trans%}, for the moment. I hope that in future volt can extend {%%}.

https://docs.phalcon.io/en/latest/reference/volt.html

But you can just use:

{{ _('submittedBy', ['username':author.username, 'created':node.created]) }}