Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3 TypoScript: Language file with arguments

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;
  }
}
like image 792
Tobias N. Avatar asked Sep 05 '25 03:09

Tobias N.


1 Answers

If your problem is only the %s part, then you could use stdwrap.replacement to process that:

  stdWrap.replacement {
    10 {
      search = %s
      replace = Me
    }
  }

See https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Replacement/Index.html

like image 158
Susi Avatar answered Sep 08 '25 01:09

Susi