image

TYPO3 Extbase Using the locallang values in Controller with variables

To use the locallang values in our extension controller, use the following function 

TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('your.label.key','YourExtensionName', $optionalArrayWithParamsToReplaceInLocalLangString);

Example

$myvar = 'testvar';
TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('mylabel','myext',array($myvar));

and in locallang.xlf, use 

<trans-unit id="mylabel">
<source>Your variable is %s </source>
</trans-unit>