TYPO3 TypoScript: Language file with arguments

Question!

how can I render a locallang key with arguments in TypoScript? (replace the %s with a value)

<trans-unit id="author">
    <source>created by %s</source>
</trans-unit>

In Fluid it's done the following:

<f:translate key="author" arguments="{0:authorName}"/>

And now via TypoScript? I tried the following:

page.10 = TEXT    
page.10.dataWrap = {LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:author|'Me'}

=====
Solution 1 via UserFunc:

page.10 = USER_INT
page.10 {
    userFunc = FluidTranslate->main
    extensionName = my_ext
    key = tx_myext_domain_model_mymodel.author
    arguments.0 = Me
}

PHP:

<?php
class FluidTranslate
{
  public function main($content, $conf)
  {
    $extensionName = $conf['extensionName'];
    $key = $conf['key'];
    $arguments = $conf['arguments.'];

    $value = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $extensionName, $arguments);
    return $value;
  }
}
By : Tobias N.


Answers

Fluid templates support these markers (sprintf() style) because the TranslateViewHelper calls LocalizationUtility which calls vsprintf() on the resolved LLL.

However, this same processing is not available through TypoScript at the current time. Although it technically could be added as a new type of stdWrap function. Previously this feature has been suggested in a form that allowed calling any PHP function - but this was (reasonably so) rejected due to security concerns and the fact that TypoScript developers are second class citizens (compared to raw PHP) in TYPO3.

That being said there is ONE immediately available option that you could use to reproduce the behavior as an stdWrap:

There is a hook location at $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] which allows you to register a class name which implements \TYPO3\CMS\Frontend\ContentObject\ContentObjectStdWrapHookInterface that can trigger on special stdWrap configurations and perform your sprintf() or vsprintf() call on the LLL value after it is resolved.

On a side note, if you complete such a feature, it would make a lot of sense to suggest/contribute it back to TYPO3. It appears to me to be a reasonable feature request!

By : Claus Due


Since I'm currently working with TYPO3 CMS 6.2.x the userFunc worked for me.
I extended the TypoScript cause I needed to react on dynamic values, based on CONTENT in combination with select.

TypoScript:

page.99 = CONTENT
page.99 {
  table = tt_content
  select {
    uidInList = 484
    pidInList = 156
  }
  selectFields = uid

  renderObj = COA
  renderObj {

    10 = USER
    10 {
        userFunc = FluidTranslate-
By : Tobias N.


I don't think this is possible in the TEXT object yet, because for resolving the LLL: from TS the method TypoScriptFrotnendController-

By : Daniel


This video can help you solving your question :)
By: admin