You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Phalcon\Translate\Adapter\NativeArray we cannot access the whole internal translate array.
Sometimes it may help increase the performance when print the translation in view using the arrays instead of calling ( _ ) method on every word or sentence in the page especially in large pages.
For example: in beforeExecuteRoute event we can this
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
// Set translate data
$this->view->setVar('_t', $this->translator->getAll());
}
and in the view we may use this:
{{ _t['title'] }}
instead of
this.translator._('title')
Thanks
The text was updated successfully, but these errors were encountered:
@palcoder That would work for translations that do not have placeholders. So for instance if you have this:
"hi" : "Hello"
"bye" : "Goodbye"
then dumping that array out will work just fine, and you will be able to use those array elements wherever you need.
If you use placeholders though:
"hi" : "Hello :name:"
"bye" : "Goodbye :name:"
the placeholder will not be replaced by the data you pass or should pass. We don't know what the user will need to send as placeholders for any given translation string, (see above the :name: placeholder) so returning that will not help.
We can introduce the method of course but that should be only with the understanding that it will have to be just strings, not placeholders. I am thinking to check whether there are any placeholders and not return those results back.
Hello,
In Phalcon\Translate\Adapter\NativeArray we cannot access the whole internal translate array.
Sometimes it may help increase the performance when print the translation in view using the arrays instead of calling ( _ ) method on every word or sentence in the page especially in large pages.
For example: in beforeExecuteRoute event we can this
and in the view we may use this:
{{ _t['title'] }}
instead of
this.translator._('title')
Thanks
The text was updated successfully, but these errors were encountered: