Description
As @fprochazka firstly mentioned in #34, current api for form translations is inconsistent and not enough. For example:
getLabel()
does not accept translation parameters (I have usecase with 3 identical inputs for which makes sense to add their number as parameter)addRule()
error message accepts only int parameter (see Validator::formatMessage)$caption
andaddError()
have no way to pass parameters
It would be absolutely ok to be unable to pass parameters in some cases, like getLabel()
or errors. I would simply disable control translator. But they are translated by form translator instead of control translator, so translator cannot be used in whole form.
So I was forced to disable translator for whole form. But I have another form at the same page with translator enabled. And both of these forms use default error messages, which are contained in Validator::$messages. Static variable, shared between all forms. Form without translator displays form.rule.equal
as placeholders are used instead of natural language. Well, I cannot use translator for both forms as replacing messages for form without translator would cause fail in form with translator (translators usually throw exception when message without translation is given)
Also, these inconsistencies cause many wtf moments for new nette/forms users. I know a huge part of nette code and I still have these moments when I don't know if something will be translated or not.
Imagine you are user without knowledge of internals. You set translator into form. Will be your select element label, prompt and values translated? What if you disable only control translator? Each of them acts differently, headache.
It's getting much more complicated to find out under which conditions translator is used. So ability to pass parameters for translator everywhere would not really solve the problem.
Could we at least mention in docs that prefered way how to translate forms is not built-in translator and copy validator messages into a non-static instance so it could be overwritten for individual forms?
With non-statical Validator instance could be default messages translated with a simple function and keep behavior for rest forms (which may use translator) same to keep it backward compatible.