Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

{% 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?.



113.9k
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.phalconphp.com/en/latest/reference/volt.html

But you can just use:

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