Since a while the validation messages of the Form Framework are translatable. Technically this is done in the Field.html layout (that is by default used for each form element):
{error -> f:translate(id: error.code, arguments: error.arguments, package: '{element.renderingOptions.translationPackage}', source: 'ValidationErrors')}
So it looks up, whether a trans-unit with the id of the validation error exists in a “ValidationErrors.xlf” file for the current locale within the “translationPackage” (by default “TYPO3.Flow”).
If it doesn’t exist, the original error message of the validator is rendered.
I don’t remember why we didn’t do so right away, but obviously we could use the same approach for form labels, changing the template from:
{element.label -> f:format.nl2br()}...
to something like
{element.label -> f:translate(id: element.uniqueIdentifier, package: '{element.renderingOptions.translationPackage}', source: 'FormLabels')}...
Unfortunately that has some implications:
- We could use a custom source (e.g. “FormLabels” instead of “ValidationErrors”). But the translate ViewHelper throws an exception when it can’t find a corresponding xlf file in the translation package (and people might have changed that to their custom package via Settings)
- the uniqueIdentifier of a form element is prefixed with the form name (e.g. “formName-elementName”). This would avoid conflicts, but one would have to add a label for every form (with a different name), e.g. “form1-name”, “form2-name”, … The alternative would be to use only the identifier and change the identifier/translation package if you need a different label for the same form elements identifiers in different forms.
- There are more translatable strings and consequently we should make them all translatable ({element.properties.elementDescription}, Form navigation (“Previous page”, …), Checkbox labels, Select options, StaticText).
At the moment I would prefer the following approach:
- Use a new source Form for all of the form related translations (including ValidationErrors) and prefix those (e.g. validationError_<errorId>, label_<formElementIdentifie>, <formElementIdentifier>_options.<optionValue>, …).
- Use the formElementIdentifier (without the form prefix) so that it’s easier to re-use the same labels/options/… across multiple forms. To avoid conflicts there are multiple options: rename the identifier, use a different preset with a different localization package, …
We could then copy the ValidationErrors to the new xlf files in TYPO3.Flow but it would be a breaking change for users that changed the translationPackage (it would throw an exception “No XLIFF file is available for <Some.Package>::Form::<locale> in the locale chain.”).
Alternatively we could make the translationSource also configurable and/or enable label translation only via feature flag for backwards compatibility…
Feedback very welcome