Documentation · ViewHelper reference

TranslateViewHelper


Translate a key from locallang. The files are loaded from the folder "Resources/Private/Language/".

Examples

Translate key

<f:translate key="key1" />

Output

value of key "key1" in the current website language

Keep HTML tags

<f:translate key="htmlKey" htmlEscape="false" />

Output

value of key "htmlKey" in the current website language, no htmlspecialchars applied

Translate key from custom locallang file

<f:translate key="LLL:EXT:myext/Resources/Private/Language/locallang.xlf:key1" />

Output

value of key "key1" in the current website language

Inline notation with arguments and default value

{f:translate(key: 'argumentsKey', arguments: {0: 'dog', 1: 'fox'}, default: 'default value')}

Output

value of key "argumentsKey" in the current website language
with "%1" and "%2" are replaced by "dog" and "fox" (printf)
if the key is not found, the output is "default value"

Inline notation with extension name

{f:translate(key: 'someKey', extensionName: 'SomeExtensionName')}

Output

value of key "someKey" in the current website language
the locallang file of extension "some_extension_name" will be used

Translate id as in TYPO3 Flow

<f:translate id="key1" />

Output

value of id "key1" in the current website language

/
  • Tag usage example

    <f:translate key="NULL" id="NULL" default="NULL" htmlEscape="1" arguments="{foo: 'bar'}" extensionName="NULL">
    	<!-- tag content - may be ignored! -->
    </f:translate>
  • Inline usage example

    {f:translate(key: 'NULL', id: 'NULL', default: 'NULL', htmlEscape: 1, arguments: {foo: 'bar'}, extensionName: 'NULL')}

Arguments

Argument Description Type
arguments

Arguments to be replaced in the resulting string

array
default

If the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default

string
extensionName

UpperCamelCased extension key (for example BlogExample)

string
htmlEscape

TRUE if the result should be htmlescaped. This won't have an effect for the default value

boolean
id

Translation Key compatible to TYPO3 Flow

string
key

Translation Key

string
Required attribute

Revision history

commit dc17dd8eab211647c17754a79000759406f97d64
Author: Christopher Hlubek <*****@networkteam.com>
Date:   Fri Mar 27 15:59:04 2009 +0000

    Ported the existing translation view helper from extbase to fluid

commit 07a35bc55b4b565a05c2ab7286911f8b72083310
Author: Christopher Hlubek <*****@networkteam.com>
Date:   Sat Mar 28 16:15:30 2009 +0000

    Initialize translate view helper only once per request

commit e060167e4b64347bbce1466dec8382bf2d9e8298
Author: Niels Pardon <*****@niels-pardon.de>
Date:   Fri Apr 10 10:45:16 2009 +0000

    Solved issue #3068: Fluid: TranslateViewHelper does only work once

commit bf34ac4842b87ac1c78ed154bdab1effbab167fa
Author: Jochen Rau <*****@web.de>
Date:   Mon Apr 13 23:01:33 2009 +0000

    Fluid:
    * Changed ExtBase to Extbase (fixes Bug #3075)

commit c31e706c772ea0538792fd0abe0c0b3062242a65
Author: Jochen Rau <*****@web.de>
Date:   Wed Apr 15 09:14:37 2009 +0000

    Fluid:
    * Some adjustments to the code according to the renaming of "blogexample" to "blog_example"

commit 240cf1d62dc0a43f54a4e64fafd1a7f6650267bb
Author: Jochen Rau <*****@web.de>
Date:   Tue May 5 10:07:39 2009 +0000

    Fluid:
    * !!!Changed signature of the URIViewHelper methods
    * Moved the assignment of the 'view' from initializeView() to the constructor

commit 38ebcedd944471b83d9293b648264fd3e65634f1
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue May 5 20:52:33 2009 +0000

    Fluid:
    * Changes backported from FLOW3:
      * major cleanup and refactoring of core and view helper classes & comments
      * added validation for boolean arguments in AbstractViewHelper
      * added initialize-method to AbstractViewHelper, that is called before render(). This was especially needed for tagbased viewhelpers.
      * renderChildren() now directly calls evaluateChildNodes() on the respective view helper node allowing us to render objects/arrays.
      * improved boolean type conversion for arguments in ViewHelperNode.
      * added TagBuilder class, re-wrote all tag based view helpers to use it (see form view helpers for some examples)
      * ViewHelperArguments collection got a new method "hasArgument()" that returns TRUE when the specified argument exists and is not NULL
    * tx_fluid changes:
      * Improved fake object factory. Now objects are injected to subclasses and implementations of the specified classes/interfaces.
      * cleaned up and tweaked view helpers. Removed Parsefunc, Stdwrap and TypoScript view helpers for now. Added CObject, If/Then/Else, EmailLink, Crop, Currency, Debug, HTML, Nl2br, Image view helpers. Thanks to Sebastian Böttger, Christopher Hlubek, Niels Pardon, Andreas Pattynama for the help!
    * Note: Unit tests not fully backported yet.

commit 1c33c299575f821dafc5b2f246ae2ea99e5ec0d5
Author: Bastian Waidelich <*****@typo3.org>
Date:   Fri May 8 11:07:09 2009 +0000

    Fluid:
     * Improved Backport (prefix "Tx_Fluid..." won't be applied within comments
     * If a view helper throws a ViewHelperException, that will be caught in ViewHelperNode to be able to react differently depending on the execution context (e.g. the error message could be outputted only when the current IP is within "devIPmask"). See DateViewHelper for an example.
     * fixed EmailViewHelper. Since latest changes $this->renderChildren() returns NULL instead of an empty string if tag has no content
     * removed test code from TranslateViewHelper.. sorry
     * Modified ActionlinkViewHelper & TypolinkViewHelper according to the latest URIHelper changes
     * unit tests on their way!

commit 7cb343a686508577abbb07450120ff038083158b
Author: Jochen Rau <*****@web.de>
Date:   Fri May 8 14:20:39 2009 +0000

    Fluid::
    * Fixed FormViewHelper for $pageUid = 0
    * Supressed notice on non existing indexes in TranslatViewHelper

commit 50af6b9c08d04e3e1d4ce56a499a9a3d4b84efc3
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Thu May 28 21:45:46 2009 +0000

    Fluid:
    * Backported major changes from Fluid v5 to Fluid v4
    * !!! Many of these changes are not backwards-compatible! Please read this if you have written custom ViewHelpers!
    * Introduced Shorthand Syntax for calling ViewHelpers
    * Core:
    ** Lots of internal cleanup and refactorings.
    ** !!! Complete restructuring into subpackages.
    * ViewHelpers:
    ** !!! The base classes of ViewHelpers changed to Tx_Fluid_Core_ViewHelper_AbstractViewHelper and Tx_Fluid_Core_ViewHelper_TagBasedViewHelper. Please adjust your ViewHelpers!
    ** !!! $this->variableContainer has been renamed to $this->templateVariableContainer
    ** !!! the view is not in $this->variableContainer anymore. Currently there is no way to fetch the View from a ViewHelper.
    ** Introduced a new $this->controllerContext containing the context variables of the controller
    ** !!! The request can be now found in $this->controllerContext->getRequest()
    ** !!! The URIHelper has been renamed to URIBuilder and can be now found in $this->controllerContext->getURIBuilder()
    ** Introduced a new ViewHelperVariableContainer, available in $this->viewHelperVariableContainer to pass data between ViewHelpers. Should only be needed in very rare cases.
    ** !!! Removed <f:format.htmlEscape> ViewHelper! Please remove these declarations in your template! Escaping of object accessors is now automatically done, see next point.
    * !!! ObjectAccessors {...} are now automatically HTMLspecialChar'd if not used as an argument to a ViewHelper. This is done using a new ObjectAccessorPostProcessor. Lateron, this will be made configurable.

commit f95503326a3fc183fb492babf05758e8965f613f
Author: Bastian Waidelich <*****@typo3.org>
Date:   Sun Jun 21 21:02:35 2009 +0000

    tx_fluid:
    * translate view helper: added support for LLL-references. Resolves #3525
    * translate view helper: small refactoring and code/comment tweaks, added unit test case (still needs more tests)
    * !!! translate view helper: default values are not HTMLEscaped anymore, so you can write <f:translate key="nonexistingKey">fallback with <strong>HTML tags</strong></f:translate>

commit 82b4e6e3b1126761471656f160946e3a1c06945f
Author: Jochen Rau <*****@web.de>
Date:   Tue Sep 15 14:25:42 2009 +0000

    [+BUGFIX] Fluid (ViewHelpers): Fixed TranslateViewHelper. LLLabels can now be overwritten via TS (plugin.tx_blogexample.settings._LOCAL_LANG .default.read_more = more).

commit a737739af5637ab6b5a19cfd7eb41d646b4c020c
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Sep 17 12:44:23 2009 +0000

    [+FEATURE] Fluid (Viewhelpers): Added backend mode support for view helpers base, cObject, format.crop (partly), link.email, translate (partly), uri.email. Now only image- and renderFlashMessages view helpers are not working in BE

commit ff44e717bfec159d9ce96917bd10c26bf613672b
Author: Bastian Waidelich <*****@typo3.org>
Date:   Wed Sep 23 15:33:06 2009 +0000

    [+FEATURE] Fluid(ViewHelpers): Added BE view helpers be.container, be.buttons.csh, be.buttons.icon, be.menus.actionMenu, be.pageInfo & be.tableList. NOTE: BE view helpers are still experimental and subject of change!
    [+FEATURE] Fluid(ViewHelpers): TranslateViewHelper now fully works in BE mode and respects BE user language. This relates to #3292
    [~BUGFIX] Fluid(ViewHelpers): Email addresses are now prepend with "mailto:" in uri.email view helper (BE mode)
    [+TASK] Fluid(ViewHelpers): uri.resource view helper now prepends "../" to relative URIs in BE mode
    [~BUGFIX] Fluid(Tests): Fixed some unit tests so that they run green. We still need more tests and a way to simulate FE mode from phpunit.

commit a0140f628afbb3cd7a0ebdd600b13d423fc71a5a
Author: Bastian Waidelich <*****@typo3.org>
Date:   Mon Sep 28 20:59:02 2009 +0000

    [+BUGFIX] Fluid(ViewHelpers): Replaced calls to $GLOBALS['LANG'] by $GLOBAL['TSFE'] if $GLOBALS['LANG'] is not available. This fixes #4794

commit dbfb03915fbc67eb2e754fc767c14c5a5ed56375
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Mon Oct 5 15:08:38 2009 +0000

    [TASK] BlogExample: Adjusted TypoScript _LOCAL_LANG settings as needed in recent commit. Related to #4905.

commit dc6ebe74cc6eaed9a395a84a4420eed7cacc63f2
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Mon Oct 5 15:09:59 2009 +0000

    * Small bugfix. sorry guys :-)

commit 9645bea1ce799e1aa940ba55b05b83c0c69d7505
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Mon Oct 26 09:48:45 2009 +0000

    [+FEATURE] Extbase (Utility): Localization Helper now supports sprintf format strings and an optional array argument. Most of this patch has been provided by Bastian. Relates to #4858. Resolves #5003
    [+FEATURE] Fluid (Utility): Translation ViewHelper now supports sprintf format strings and an optional array argument. Relates to #5003
    [~TASK] Viewhelpertest: Adjusted examples for f:translate. Relates to #5003

commit 71eb52f289bd61c2ec12dd8a86007cfe92b755a2
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Oct 29 11:20:10 2009 +0000

    [+FEATURE] Fluid (ViewHelpers): extended cObject viewhelper by an additional "data" argument. Now you can write {f:cObject(typoscriptObjectPath: 'lib.someCObject', data: someObject)} in your templates. This change is backwards compatible! Relates to #5150
    [+FEATURE] Fluid (ViewHelpers): extended translate viewhelper by an additional "default" argument. Now you can write {f:translate(key: 'someLocallangKey', default: 'some fallback')} in your templates. This change is backwards compatible! Relates to #5150

commit 06372a84a645147029501d2b2b06a4fdfe56b7d7
Author: Michael Stucki <*****@typo3.org>
Date:   Wed Nov 25 21:53:57 2009 +0000

    Add missing SVN properties for new or modified files

commit 186bdaeac89820779f91853b830cc95d60c7ad58
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 09:42:26 2010 +0000

    [-TASK] Fluid: R*****@version annotation from all Fluid classes to ease the backporting process. Relates to #8835 (backported from Fluid package)

commit 1d36de6ed90007e324b773782e8f0a1d1c1191a2
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 10:12:30 2010 +0000

    [-TASK] Fluid: R*****@package/@subpackage annotations from all Fluid classes. They have already been removed in FLOW3 packages in r2813.

commit dd8928aed4c119d8db37322acb91ded24ba5cc35
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Dec 30 16:21:11 2010 +0000

    [+TASK] Fluid (ViewHelpers): Fix, cleanup and extend inline documentation of ViewHelpers
    
    Resolves #10908

commit fd09d197fa8886b97cb20aa9573f39cd08ce989e
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Nov 10 18:27:58 2011 +0100

    [TASK] S*****@author annotations
    
    This backports three recent changes of the TYPO3.Fluid package:
    - R*****@license annotation from files (290f4f5)
    - Simplify license header in PHP files (14bacba)
    - D*****@author tags from source code (9c2e837)
    
    This should not contain any functional change!
    
    Change-Id: I9376dca4af78c4f0f82413011d115b8ad04634dd

commit ca40f8a066da4ea3c849d74f68a9bc73758976c5
Author: dkd-egerer Sascha Egerer <*****@dkd.de>
Date:   Sat Apr 14 21:43:10 2012 +0200

    [TASK] Remove trailing whitespace
    
    There must be no empty lines after the closing
    PHP tag. Empty lines after closing tags break
    output compression in PHP and/or result in AJAX
    errors.
    
    Change-Id: I0484ca29d8134d0828cf30880d5aafd43ed9d78e
    Resolves: #36076
    Releases: 6.0
    Reviewed-on: http://review.typo3.org/10499
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf
    Reviewed-by: Daniel Lorenz
    Tested-by: Daniel Lorenz
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit 8a7990831edc57c1f31ada92433b728a97919268
Author: Bastian Waidelich <*****@typo3.org>
Date:   Mon May 7 15:39:32 2012 +0200

    [FEATURE] optional "extensionName" argument for f:translate
    
    By default the Translate ViewHelper uses the current extension
    name to resolve paths to locallang files.
    This adds a new optional argument "extensionName" that can be
    specified in order to localize labels from other Extensions.
    
    Change-Id: I44b28d5f8c7765e83d686fcecebf73db1ab1d05e
    Fixes: #39882
    Related: #12502
    Releases: 6.0
    Reviewed-on: http://review.typo3.org/11049
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf

commit ec3891d8d4e339d8319428211207e6201be9fd73
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 21:18:26 2012 +0200

    [TASK][WIP] Move non class code back to source files
    
    Change-Id: I620d2e61860142cdc89cc83474c95542799961c0

commit 554e8f890dcc0dd86a27518b58e2b54be26fd37e
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 22:20:17 2012 +0200

    [TASK] Namespace classes
    
    Change-Id: Ia7432e1c923826ed58206bca15fb94509adbd508

commit 772cef9afc4b2634674f4b78b228f86571815170
Author: Ingo Pfennigstorf <*****@gmail.com>
Date:   Tue Oct 30 10:17:52 2012 +0100

    [TASK] Make Fluid translation calls compatible to TYPO3 Flow
    
    in TYPO3 Flow you can call <f:translate id="..." />
    In our Fluid you have to call <f:translate key="..." />
    
    That makes porting Extensions to to Flow packages less compatible. This
    Patch introduces a compatibility layer and let the user choose whether
    he wants to use the key argument instead of id.
    
    If both are used the "id" has a higher priority.
    
    Fixes: #42507
    Releases: 6.0
    Change-Id: I8a1f386a56480a73a64c7ccf70383a37a05bf7a5
    Reviewed-on: http://review.typo3.org/16031
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring
    Reviewed-by: Stefan Neufeind
    Reviewed-by: Alexander Schnitzler
    Tested-by: Alexander Schnitzler

commit 9d46e6932d35c79bf87c96fa38b8e537c4192f23
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Tue Nov 20 16:27:02 2012 +0100

    [CLEANUP] Adjust code to CGL and fix small namespace bugs
    
    * whitespaces, tabs and blank line issues
    * bool -> boolean
    * int -> integer
    * fix wrong namespace annotations
    
    Fixes: #43157
    Releases: 6.0
    Change-Id: I8397948e19248db029d8efd1555ee56e4982742d
    Reviewed-on: http://review.typo3.org/16619
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit b6ebd943783003be4630e4c7501ae433056cdc01
Author: dkd-egerer Sascha Egerer <*****@dkd.de>
Date:   Fri Apr 13 11:48:05 2012 +0200

    [BUGFIX] Apply arguments to the default string
    
    Apply given arguments with sprintf to the default string
    if no localization string was found.
    
    Change-Id: I42002da0b6224f04bcb340d0e451f4c0f1c929f1
    Fixes: #34877
    Related: #34874
    Releases: 6.1, 6.0, 4.7, 1.3
    Reviewed-on: https://review.typo3.org/10385
    Reviewed-by: Markus Günther
    Tested-by: Markus Günther
    Reviewed-by: Marc Bastian Heinrichs
    Tested-by: Marc Bastian Heinrichs

commit 62017812f1848f1153c2ad20df1400511c1be949
Author: Ingo Pfennigstorf <*****@gmail.com>
Date:   Thu Jul 4 22:00:27 2013 +0200

    [TASK] Remove Comment for deprecation of f:translate key
    
    In future versions the usage of f:translate key and f:translate id
    will both be possible, so the comment about a deprecation is removed.
    
    Change-Id: I71a2fc1e9abec6b26c8b3848dd31e234fc056699
    Fixes: #49670
    Releases: 6.2, 6.1, 6.0
    Reviewed-on: https://review.typo3.org/21896
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit 36b5914f6b26fb50ed82446990250f9e766bfd42
Author: Wouter Wolters <*****@wouterwolters.nl>
Date:   Tue Jul 9 21:57:29 2013 +0200

    [TASK] Move language include to .xlf
    
    Move all old language includes (php,xml) in the core to .xlf
    
    Change-Id: I804b5970a360cbfdc2940736632c55c535ccbd40
    Resolves: #49832
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/22167
    Reviewed-by: Markus Klein
    Reviewed-by: Georg Ringer
    Tested-by: Georg Ringer

commit 77f29a3c69a7cbb27b34072754aa503bace6c9f1
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Tue Oct 1 14:40:56 2013 +0200

    [TASK] Remove closing PHP tags
    
    Change-Id: Iaa92566c53301e49396fc9fb26b0b339c48d567b
    Resolves: #52360
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/24212
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Ernesto Baschny
    Tested-by: Ernesto Baschny
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit de27a20afbd8f413f60029afc5622c7b33212322
Author: Markus Klein <*****@mfc-linz.at>
Date:   Sun Feb 23 11:21:20 2014 +0100

    [CLEANUP] Replace strlen() with === for zero length check
    
    It is faster to compare a string with === '' to find out if it's empty
    than to run strlen() on it.
    
    The replacement rules are applied as follows:
     *    if (strlen($str))
       => if ((string)$str !== '')
     *    if (!is_string($str) || strlen($str) === 0)
       => if (!is_string($str) || $str === '')
     * If it can be seen easily that $str is a string,
       the typecast is omitted.
    
    Resolves: #54091
    Releases: 6.2
    Change-Id: I59c5cbccea4f98b8f282377e6aa67d970859a457
    Reviewed-on: https://review.typo3.org/27091
    Reviewed-by: Stefan Neufeind
    Tested-by: Stefan Neufeind

commit 945911006229524d55cb48f1f7de0898be9a7b7f
Author: Stefan Neufeind <*****@speedpartner.de>
Date:   Sun Feb 23 12:34:13 2014 +0100

    Revert "[CLEANUP] Replace strlen() with === for zero length check"
    
    This reverts commit de27a20afbd8f413f60029afc5622c7b33212322
    
    Change-Id: I078d2f7bbff605c91d83a9853e8feb9c31d57ccc
    Reviewed-on: https://review.typo3.org/27792
    Reviewed-by: Stefan Neufeind
    Tested-by: Stefan Neufeind