Empty value when trying to read XML data

252 Views Asked by At

In my plugin I am trying to read data from the file locallang.xml using the Typo3 function pi_getLL().

PHP

$this->pi_loadLL();
var_dump($this->pi_getLL('test'));

XML

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
    <meta type="array">
        <type>module</type>
        <description>Language labels for plugin &quot;tx_fzswettbewerbsg_pi2&quot;</description>
    </meta>
    <data type="array">
        <languageKey index="default" type="array">
            <label index="test">German</label>
        </languageKey>
        <languageKey index="fr" type="array">
            <label index="test">France</label> 
        </languageKey>
    </data>
</T3locallang>

When I run this script, I always get an empty string:

string(0) ""

Why is var_dump() not returning the values from my XML?

1

There are 1 best solutions below

0
Ghanshyam Gohel On

*following solution for TYPO3 v4.7x

This must be work as in your question:

public function main($content, array $conf) {
   $this->conf = $conf;
   $this->pi_loadLL();

   $this->pi_getLL('label_index_name', 'alternative-text', 0); // 0 or 1 If TRUE, the output label is passed through htmlspecialchars() 
}

you can get label using global variables like: Reference

public function main($content, array $conf) {

    $GLOBALS['LANG']->sL('LLL:EXT:your_ext/locallang.xml:label_index_name'); 
    // OR

    $LL = $this->includeLocalLang();
    $GLOBALS['LANG']->getLLL('label_index_name', $LL);
}

public function includeLocalLang() {
    $llFile = t3lib_extMgm::extPath('your_ext') . 'locallang.xml';
    $version = class_exists('t3lib_utility_VersionNumber')
            ? t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version)
            : t3lib_div::int_from_ver(TYPO3_version);
    if ($version < 4006000) {
        $LOCAL_LANG = t3lib_div::readLLXMLfile($llFile, $GLOBALS['LANG']->lang);
    } else {
        /** @var $llxmlParser t3lib_l10n_parser_Llxml */
        $llxmlParser = t3lib_div::makeInstance('t3lib_l10n_parser_Llxml');
        $LOCAL_LANG = $llxmlParser->getParsedData($llFile, $GLOBALS['LANG']->lang);
    }

    return $LOCAL_LANG;
}

One another trick ;)

Tx_Extbase_Utility_Localization::translate('label_index_name', $extensionName, $arguments=NULL);