@@ -15,21 +15,85 @@ Translate ViewHelper `<f:translate>`
1515.. seealso ::
1616 * `Working with XLIFF files <https://docs.typo3.org/permalink/t3coreapi:xliff-api >`_
1717 * `Multi-language Fluid templates <https://docs.typo3.org/permalink/t3coreapi:extension-localization-fluid >`_
18+ * `Label references / Translation domains <https://docs.typo3.org/permalink/t3coreapi:label-reference >`_
19+ * `Feature: #107759 - TranslateViewHelper supports Translation Domain syntax <https://docs.typo3.org/permalink/changelog:feature-107759-1729433323 >`_
1820
1921.. contents :: Table of contents
2022
23+ .. note ::
24+ .. versionadded :: 14.0
25+ The translate ViewHelper supports `translation domains <https://docs.typo3.org/permalink/t3coreapi:label-reference >`_,
26+ a short and convenient way to reference language labels without
27+ requiring `LLL: ` paths or extension names.
28+
29+ Translation domain syntax is the **recommended ** and **future-proof ** way
30+ to reference translations.
31+
32+ The older `LLL: ` and `extension ` arguments are still valid for
33+ **backward compatibility **.
34+
35+ All existing syntax remains fully supported, ensuring backward
36+ compatibility. The new syntax can be adopted incrementally within a
37+ project, and both old and new forms can coexist in the same template.
38+
2139.. _typo3-fluid-translate-example :
40+ .. _typo3-fluid-translate-example-domain :
41+
42+ Using translation domains
43+ =========================
44+
45+ The translation domain syntax is the **recommended ** way to
46+ reference labels. It allows concise and clear label identifiers, without using
47+ `LLL: ` paths and extension names.
48+
49+ There are two equivalent ways to use domains:
50+
51+ 1. **Provide the domain as a separate argument ** and only reference the identifier
52+ (recommended):
53+
54+ .. code-block :: html
55+
56+ <f:translate domain =" backend.toolbar" key =" save" />
57+ <f:translate domain =" my_extension.messages" id =" greeting.hello" />
58+
59+ 2. **Use the combined domain + identifier syntax ** in the `key `/`id ` arguments:
60+
61+ .. code-block :: html
2262
23- Examples
24- ========
63+ <f:translate key =" backend.toolbar:save" />
64+ <f:translate id =" my_extension.messages:greeting.hello" />
65+
66+ * The **domain ** syntax is the preferred syntax for all new templates.
67+ * If both `domain ` and `extension ` are set, **the domain property takes precedence **.
68+ * The older `key="LLL:EXT:..." ` and `extension ` arguments are still supported for
69+ backward compatibility.
70+
71+ .. tip ::
72+ Run the console command to list all translation domains and their language
73+ file mapping:
74+
75+ .. code-block :: bash
76+
77+ vendor/bin/typo3 language:domain:list
78+
79+ This will help you find your domains when migrating from `LLL: ` paths
80+ to the new translation domain syntax.
81+
82+ .. _typo3-fluid-translate-example-backward :
83+
84+ Backward compatible syntax
85+ ==========================
86+
87+ The following forms are still supported for older templates and extensions.
88+ New code should use domains instead.
2589
2690.. _typo3-fluid-translate-example-key-only :
2791
2892Short key - Usage in Extbase
2993----------------------------
3094
3195The :ref: `key <t3viewhelper:viewhelper-argument-typo3-cms-fluid-viewhelpers-translateviewhelper-key >`
32- argument alone works only within the Extbase context.
96+ argument on its own works in the Extbase context.
3397
3498.. tabs ::
3599
@@ -45,29 +109,34 @@ argument alone works only within the Extbase context.
45109 :language: xml
46110 :caption: packages/my_extension/Resources/Private/Language/locallang.xlf
47111
48- Alternatively, you can use `id ` instead of `key `, producing the same output.
112+ Alternatively, you can use `id ` instead of `key ` to produce the same output.
49113If both `id ` and `key ` are set, `id ` takes precedence.
50114
51115If the translate ViewHelper is used with only the language key, the template
52- **must ** be rendered within an Extbase request, usually from an Extbase
116+ **must ** be rendered in an Extbase request, usually from an Extbase
53117controller action. The default language file must be located in the same
54- extension as the Extbase controller and must be saved in the file
118+ extension as the Extbase controller and must be saved in
55119:file: `Resources/Private/Language/locallang.xlf `.
56120
57121.. _typo3-fluid-translate-example-key-extension :
58122
59123Short key and extension name
60124----------------------------
61125
62- When the ViewHelper is called from outside Extbase, it is mandatory to either
63- pass the extension name or use the full `LLL: ` reference for the key .
126+ If the ViewHelper is called from outside Extbase, the extension name or the
127+ full `LLL: ` key reference must be passed as arguments .
64128
65129.. code-block :: html
66130
67131 <f:translate key =" domain_model.title" extension =" my_extension" />
68132
69- The default language file must be saved in the extension specified in the
70- argument, in the file :file: `Resources/Private/Language/locallang.xlf `.
133+ The default language file must be located in
134+ :file: `Resources/Private/Language/locallang.xlf ` of the extension.
135+
136+ .. versionchanged :: 14.0
137+ The translation domain syntax is now the recommended way
138+ to reference labels. The `extension ` argument still works for
139+ backward compatibility.
71140
72141.. _typo3-fluid-translate-example-key-full :
73142
@@ -83,10 +152,13 @@ file can be used.
83152 key =" LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:domain_model.title"
84153 />
85154
155+ .. note ::
156+ This legacy form remains fully supported for backward compatibility.
157+ Domain syntax should be used for all new templates.
86158.. _typo3-fluid-translate-example-html :
87159
88160Keeping HTML tags within translations
89- -------------------------------------
161+ =====================================
90162
91163HTML in language labels can be used when you surround the translate ViewHelper
92164with a ViewHelper that allows HTML output, such as the
@@ -102,7 +174,8 @@ in the frontend.
102174
103175 <f:format .html >
104176 <f:translate
105- key =" LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:myKey"
177+ domain =" my_extension.messages"
178+ key =" content.withHtml"
106179 />
107180 </f:format .html >
108181
@@ -121,7 +194,7 @@ The entry in the `.xlf` language file must be surrounded by `<![CDATA[...]]>`.
121194.. _typo3-fluid-translate-example-placeholder :
122195
123196Displaying translated labels with placeholders
124- ----------------------------------------------
197+ ==============================================
125198
126199.. tabs ::
127200
@@ -130,14 +203,16 @@ Displaying translated labels with placeholders
130203 .. code-block :: html
131204
132205 <f:translate
133- key =" LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:domain_model.title"
206+ domain =" my_extension.domainmodel"
207+ key =" title"
134208 arguments =" {0: '{myVariable}'}"
135209 />
136210
137211 Or with several numbered placeholders:
138212
139213 <f:translate
140- key =" LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:domain_model.title"
214+ domain =" my_extension.domainmodel"
215+ key =" title"
141216 arguments =" {1: '{myVariable}', 2: 'Some String'}"
142217 />
143218
@@ -154,34 +229,34 @@ subsequent array entries in order.
154229To avoid dependency on order, use indexed placeholders like `%1$s `. This
155230explicitly refers to the first value and ensures that it is treated as a string
156231(`$s `). This method is based on PHP’s
157- `vsprintf function <https://www.php.net/manual/en/function.vsprintf.php> `,
232+ `vsprintf function <https://www.php.net/manual/en/function.vsprintf.php >`_ ,
158233which allows for more flexible and readable formatting.
159234
160235.. _typo3-fluid-translate-example-inline :
161236
162237Inline notation with arguments and default value
163- ------------------------------------------------
238+ ================================================
164239
165- Like all other ViewHelpers, the translate ViewHelper can be used with the
240+ Like all the other ViewHelpers, the translate ViewHelper can be used with
166241`Inline syntax <https://docs.typo3.org/permalink/fluid:viewhelper-inline-notation >`_.
167242
168243.. code-block :: html
169244
170- {f:translate(key: 'someKey ', arguments: {0: 'dog', 1: 'fox'}, default: 'default value')}
245+ {f:translate(domain: 'my_extension.messages', key: 'animal.sentence ', arguments: {0: 'dog', 1: 'fox'}, default: 'default value')}
171246
172247This is especially useful if you want to pass the translated label to another
173248ViewHelper, for example, as the `alt ` parameter of an image:
174249
175250.. code-block :: html
176251
177252 <f:image src =" EXT:my_extension/Resources/Public/icons/Edit.svg"
178- alt =" {f:translate(key : 'icons. edit', default: 'Edit')}"
253+ alt =" {f:translate(domain : 'my_extension.icons', key: ' edit', default: 'Edit')}"
179254 />
180255
181256.. _typo3-fluid-translate-example-console :
182257
183258The translation ViewHelper in console/CLI context
184- -------------------------------------------------
259+ =================================================
185260
186261The translation ViewHelper determines the target language based on the current
187262frontend or backend request.
@@ -195,21 +270,29 @@ to specify the desired language for the ViewHelper:
195270
196271 Salutation in Danish:
197272 <f:translate
198- key =" LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:salutation"
273+ domain =" my_extension.messages"
274+ key =" salutation"
199275 languageKey =" da"
200276 />
201277
202278 Salutation in English:
203279 <f:translate
204- key =" LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:salutation"
280+ domain =" my_extension.messages"
281+ key =" salutation"
205282 languageKey =" default"
206283 />
207284
285+
208286.. _typo3-fluid-translate-arguments :
209287
210288Arguments of the f:translate ViewHelper
211289=======================================
212290
291+ .. versionadded :: 14.0
292+ The `domain ` argument was added. It selects a **translation domain **
293+ and should be preferred over `extension ` or `extensionName `.
294+ When both are given, `domain ` takes precedence.
295+
213296.. typo3 :viewhelper :: translate
214297 :source: /Global.json
215298 :display: arguments-only
0 commit comments