Feature: #107759 - TranslateViewHelper supports Translation Domain syntax
See forge#107759
Description
The Fluid
<f: ViewHelper now supports the new
Translation Domain syntax,
providing a more concise and readable way to reference translation labels.
A new
domain attribute has been added that accepts both traditional
extension names and the new translation domain names.
The ViewHelper now supports multiple ways to specify translations:
-
New domain attribute - Recommended for new code:
<f:translate key="form.legend" domain="my_extension" /> <f:translate key="form.legend" domain="my_extension.messages" />Copied! -
Inline domain syntax in key - Shortest form:
<f:translate key="my_extension.messages:form.legend" /> <f:translate key="LLL:my_extension.messages:form.legend" />Copied! -
Traditional extensionName attribute - Still supported:
<f:translate key="form.legend" extensionName="MyExtension" /> <f:translate key="form.legend" extensionName="my_extension" />Copied! -
Full LLL reference - Classic syntax, still supported:
<f:translate key="LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:form.legend" />Copied!
Domain Attribute Priority
When both
domain and
extension are provided, the
domain attribute takes precedence:
<!-- Uses "other_extension.messages" domain, not "MyExtension" -->
<f:translate key="label" domain="other_extension.messages" extensionName="MyExtension" />
Automatic Domain Detection
If neither
domain nor
extension are specified, the
ViewHelper attempts to automatically detect the translation domain from the
context:
- Extbase context: Uses the controller extension name
- Key with domain prefix: Extracts domain from
key="domain:syntaxid" - LLL reference: Parses the extension key from the file path
Examples
Using domain attribute with full domain name
You can specify the exact translation domain including resource names:
<f:translate key="menu.item" domain="backend.toolbar" />
<!-- Resolves to: EXT:backend/Resources/Private/Language/locallang_toolbar.xlf -->
Inline domain syntax in key
The shortest form combines domain and key directly:
<f:translate key="core.form.tabs:general" />
<!-- Resolves to: EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf -->
With arguments and default values
All existing ViewHelper features work with the new syntax:
<f:translate
key="users"
domain="backend.messages"
arguments="{0: count}"
default="No users found"
/>
Using variables for domain
Dynamic domain selection is supported:
<f:translate key="label.title" domain="{myDomain}" />
Migration from extensionName
Existing code using
extension continues to work without changes.
However, new code should prefer the
domain attribute combined with
translation domain syntax for better readability:
Before:
<f:translate key="LLL:EXT:my_extension/Resources/Private/Language/locallang_form.xlf:legend" />
<f:translate key="legend" extensionName="MyExtension" />
After:
<f:translate key="my_extension.form:legend" />
<f:translate key="legend" domain="my_extension.form" />
Impact
The
<f: ViewHelper now provides a more convenient and
readable way to reference translations using the new translation domain syntax.
This reduces verbosity in Fluid templates and aligns with modern translation
system conventions used in Symfony and other frameworks.
All existing syntax forms remain fully supported, ensuring backward compatibility. The new syntax can be adopted incrementally within a project, and both old and new forms can coexist in the same template.