[TYPO3-dev] How to get language label for a custom table from plugin code?

Bernd Wilke xoonsji02 at sneakemail.com
Sat Mar 11 01:24:42 CET 2006


On Fri, 10 Mar 2006 14:29:54 -0300, Ricardo Scachetti Pereira wrote
with subject "[TYPO3-dev] How to get language label for a custom table from
plugin code?":

>     Hello all,
> 
>     How can I get a set of language labels from a custom table from a 
> plugin class function?
> 
>     More specifically, I'm coding a plugin and I'm trying to display the 
> contents of a field that is select box (type select). The labels for 
> each field valid value are defined on the LOCAL_LANG array in 
> locallang_db.php file of my plugin.
> 
>     In other words, I wanted something equivalent to the function 
> class.tslib_pibase::pi_getLL().
> 
>     Any help is greatly appreciated.
> 
>     Best regards,
> 
> Ricardo

my special solution in my FE-Plugin(s):

in method main():

// include the locallang_db.php and return the definition to store it in a
variable
$this->LL = $this->includeLocalLang();			

// from kickstarter:
$this->LANG = t3lib_div::makeInstance('language');
$LLkey = 'default';
if ($GLOBALS['TSFE']->config['config']['language']) {
    $LLkey = $GLOBALS['TSFE']->config['config']['language'];
}
$this->LANG->init($LLkey);

$this->pi_loadLL();


and these two new methods
// ========================================================================
/**
 * replacement of my_getLL:
 * if there is no definition in the (plugin-)local locallang.php
 * look in the extension-global locallang_db.php
 *
 * @param	string	see my_getLL() (key)
 * @param	string	see my_getLL() (alternate text if not found)
 * @param	bool	see my_getLL() (htmlSpecificCharacters)
 * @return	string	string, languagedependent

 */
function my_getLL($s,$alt='',$hsc=TRUE) {
	$retval=$this->pi_getLL($s,'',$hsc);
	if (!$retval) {
		$l = t3lib_div::makeInstance('language');
		$retval = $this->LANG->getLLL($s,$this->LL,$hsc);
	}
	if (!$retval) $retval=$alt;
	if (!$retval) $retval='['.$s.']';
	return $retval;
}
// ========================================================================
/**
 * include the BE-locallang and return the definition to store it in a
variable
 * @return array
 */
function includeLocalLang()    {
	include(t3lib_extMgm::extPath($this->extKey).'locallang_db.php');
	return $LOCAL_LANG;
}
// ========================================================================


then you always can use this method
	$this->my_getLL('something')
instead of:
	$this->pi_getLL('something')

and special for fieldnames/valuenames from  the tables:

	$table = 'name_of_my_table';
	$fN = 'fieldname_in_my_table';
        $fN = 'status.I.3';		// valuename of checkbox-selection

	$this->my_getLL('tx_'.$this->extKey.'_'.$table.'.'.$fN);

with this I can access the names of my new tables (fieldnames, valuenames)
without redefinition everything for every plugin (I have three FE-Plugins,
who wants to synchronize four lists?)
Also I can redefine a name in a single plugin within plugin-local
locallang.php or plugin specific typoscript-redifinition

my_getLL() returns a string:

value from pluginspecific locallang.php (or typoscript-definition)
or (if empty)
value from locallang_db.php
or (if empty)
value of parameter 'alt'
or (if empty)
key in square-brackets	// this never is empty

Bernd Wilke

-- 
----------------
Bernd Wilke     
Annweilerstr.20 
40229 Düsseldorf
0211/229 2800




More information about the TYPO3-dev mailing list