The first thing we need to do is importing the LocalizationUtility:


use TYPO3\CMS\Extbase\Utility\LocalizationUtility;


Then we can use the static method translate  to get the value of our translation.


Case 1:


LocalizationUtility::translate('LLL:EXT:myext/Resources/Private/Language/locallang_hardware.xlf:type', '');


We need to add the path of our language file and the trans-unit key if we wanna use multiple language files. LLL: defines the passed value as a language-label.


Case 2:


LocalizationUtility::translate('tx_myext_domain_model_hardware.type'', 'myext');


You can use this way if you just use the locallang.xlf inside your extension (Resources/Private/Language/locallang.xlf) . In that case the first parameter equals the trans-unit key and the second parameters your extension key.


Inside fluid templates you should use the f:translate view helper. Like in extbase there are multiple cases too.


Case 1:


<f:translate key="tx_myext_domain_model_hardware.type"/>


The same functionality but inline style:


{f:translate(key: 'tx_myext_domain_model_hardware.type')} 


In this case the view helper uses the locallang.xlf inside your extension:




Translations must be added to the locallang.xlf file and cannot be added to other files with this example.


Case 2:


<f:translate key="LLL:EXT:myext/Resources/Private/language/locallang_hardware.xlf:type"/>


This is your case if you have more than one language file. LLL: defines the key as an language label that contains the path to the file and the trans-unit key. In this example the file name is:




It´s recommended but not required to store the language file inside your extension. If the language file is inside the fileadmin or other folders you could use LLL:fileadmin/bad_idea_to_do_that/locallang.xlf:my_key .


No Comments

Write comment

* These fields are required