Feature: #97637 - Translate default value of form elements
See forge#97637
Description
The TYPO3 Form Framework now supports translating the
default
property of form elements via XLF translation files.
Previously, only properties like
label,
placeholder and
rendering options could be translated through the form framework's translation
mechanism. The
default property was always rendered as-is from the
form definition, regardless of the current frontend language.
With this change, the
default is translated before rendering using
the same XLF key conventions already established for other form element
properties. The translation is resolved in the following order (first match wins):
<form-definition-identifier>.element.<element-identifier>.properties.defaultValueelement.<element-identifier>.properties.defaultValueelement.<element-type>.properties.defaultValue
Example
Given a form element defined as:
identifier: contact-form
type: Form
prototypeName: standard
renderables:
- type: Page
identifier: page-1
renderables:
- type: Text
identifier: bestDish
label: 'Best dish?'
defaultValue: 'Hamburger'
renderingOptions:
translation:
translationFiles:
- 'EXT:my_extension/Resources/Private/Language/Form/locallang.xlf'
The translation file can now provide a translated default value:
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="de" datatype="plaintext" original="messages">
<body>
<trans-unit id="contact-form.element.bestDish.properties.defaultValue">
<source>Hamburger</source>
<target>Kartoffel</target>
</trans-unit>
</body>
</file>
</xliff>
Or, to apply the translation to all
Text elements across all forms:
<trans-unit id="element.Text.properties.defaultValue">
<source>Hamburger</source>
<target>Kartoffel</target>
</trans-unit>
Impact
Form integrators can now provide language-specific default values for form elements.
The translation is applied automatically before rendering using the existing
translation file configuration in
rendering.
Array-based
default properties are intentionally excluded from
translation. These occur on multi-value elements like
Multi or
Multi, where the values are option keys that must match the
configured
properties. exactly. Translating them would break the
value-to-option mapping. The option labels themselves can be translated via the
existing
properties. translation mechanism.