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;
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With