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

Is good practice translate strings in the template?

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

<h1> {{ _('title') }}</h1>

I think we should move on to the template, translated variables.

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.

I think it's best to use gettext, for performance and ease translate chains.

A DB approach would kill the application, using Array is hard to maintain.

I have seen the code drupal 8 and the views there over 8000 {% trans%}. GettextPHP use a component, if resource-intensive only translate strings.



145.0k
Accepted
answer

But phalcon translate can actually use gettext so no problem here :)

Missing doc. :)

but work fine.

$translator = new \Phalcon\Translate\Adapter\Gettext([
                'category'      => $this->category,
                'locale'        => $this->locale . '.utf8',
                'defaultDomain' => $this->defaultDomain,
                'directory'     => $this->directory 
]);

$translator->query('All work fine!');