我该如何在TypoScript中使用参数替换局部语言键(将%s替换为值)进行呈现?
在 Fluid 中,做以下操作:
<trans-unit id="author">
<source>created by %s</source>
</trans-unit>
在 Fluid 中,做以下操作:
<f:translate key="author" arguments="{0:authorName}"/>
现在通过TypoScript怎么做呢?我尝试了以下方法:
page.10 = TEXT
page.10.dataWrap = {LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:author|'Me'}
=====
通过UserFunc的解决方案1:
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;
}
}