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
Support for message key prefix #21
Conversation
$me->addMacro( | ||
'translatePrefix', | ||
'$presenter->translator->setPrefix(%node.args)', | ||
'$presenter->translator->resetPrefix()' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should nott be here $template
instead of $presenter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With $template
it throws: "The variable 'translator' does not exist in template."
You'd have to add this variable somewhere in BasePresenter createTemplate():
$template->translator = $this->translator;
And I think this is unnecessary step.
Please, see changes - there is typo in indention. It must be fixed, thanks. |
I think it's wrong to have this in the Translator class. However I do think it could be useful in templates. The macro |
It certainly doesn't belong to translator and the indentation is horrible :) Better would be to create a class PrefixedTranslator which would wrap existing translator and at the end of the macro it will then unwrap it. Fyi there is an issue for this :) #3 |
Sorry for indentation. It works bad with my IDE. I think it should be in Translator class (or PrefixedTranslator for example) because then you can use it both in PHP and template. |
The problem with adding it directly to Translator class is a global state, which will be a problem, when you use the translator in presenters and forms. |
Thank you for your time, would you mind testing the new macro? I'm also open to better naming if anyone has a thought. Please let any further discussion happen at #3 |
This feature simplify writing of translate keys in templates. Example of Nette template:
messages.en_EN.neon file:
You appreciate this, when you'r preparing large Nette templates for translation. Writing/copying same prefix of keys is really annoying.