Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFR]: Get the internal translate array in Translate NativeArray #15902

Closed
palcoder opened this issue Feb 11, 2022 · 3 comments · Fixed by #15968
Closed

[NFR]: Get the internal translate array in Translate NativeArray #15902

palcoder opened this issue Feb 11, 2022 · 3 comments · Fixed by #15968
Labels
new feature request Planned Feature or New Feature Request

Comments

@palcoder
Copy link

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

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

@palcoder palcoder added the new feature request Planned Feature or New Feature Request label Feb 11, 2022
@niden
Copy link
Sponsor Member

niden commented Feb 11, 2022

@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.

Thoughts?

@someson
Copy link

someson commented May 12, 2022

almost the same problem i faced trying to extend the NativeArray in order to aggregate some data from translate class var:
#15958

@niden niden mentioned this issue May 23, 2022
5 tasks
@niden niden linked a pull request May 23, 2022 that will close this issue
5 tasks
@niden
Copy link
Sponsor Member

niden commented May 23, 2022

Resolved in #15968

Thank you @palcoder

@niden niden closed this as completed May 23, 2022
@niden niden added this to Implemented in Phalcon Roadmap May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
Archived in project
Phalcon Roadmap
  
Implemented
Development

Successfully merging a pull request may close this issue.

3 participants