How to read locallang file in typo3 custom extension.


 
For multi language site locallang file is very important for set all labels language wise.

First of all we have to set path for xml file which we have to read. So for that we will use following code.

This is for EXTBASE Extension
$xmlPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('EXTENSION_NAME').'locallang_db.xml';

OR

This is for PI Base Extension
$xmlPath = t3lib_extMgm::extPath('EXTENSION_NAME').'locallang_db.xml';

Now we have to read xml file. following code should do the trick.


$curLang = "default";

This is for EXTBASE Extension
\TYPO3\CMS\Core\Utility\GeneralUtility::readLLXMLfile($xmlPath, $lang);
OR

This is for PI Base Extension
t3lib_div::readLLXMLfile($xmlPath, $lang);

For get particular language data we have to use following script.


$cfile = t3lib_extMgm::extPath('EXTENSION_NAME').'locallang_db.xml';

$curLang = "default";

$LOCAL_LANG = t3lib_div::readLLXMLfile($cfile, $curLang);

$label = $LOCAL_LANG[$curLang]['lbl_welcome_msg'];

if we wont it on other language then simply use language code in $curLang variable.

$curLang = "de";

after set “de” as language code it will display all data from related languages.

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s