Project

General

Profile

Bug #19371 ยป lang.php.diff

Administrator Admin, 2008-09-23 22:19

View differences:

typo3/sysext/lang/lang.php (working copy)
* @see typo3/template.php, template
*/
class language {
var $lang='default'; // This is set to the language that is currently running for the user
var $langSplit='default'; // Values like the labels in the tables.php-document are split by '|'. This values defines which language is represented by which position in the resulting array after splitting a value. (NOTICE: Obsolete concept!)
// This is set to the language that is currently running for the user
public $lang = 'default';
// Values like the labels in the tables.php-document are split by '|'. This values defines which language is represented by which position in the resulting array after splitting a value. (NOTICE: Obsolete concept!)
public $langSplit = 'default';
// Default charset in backend
var $charSet = 'iso-8859-1';
public $charSet = 'iso-8859-1';
// Array with alternative charsets for other languages. (Moved to t3lib_cs, Set from csConvObj!)
var $charSetArray = array();
public $charSetArray = array();
// This is the url to the TYPO3 manual
var $typo3_help_url= 'http://www.typo3.com/man_uk/';
public $typo3_help_url = 'http://www.typo3.com/man_uk/';
// Array with alternative URLs based on language.
var $helpUrlArray = array(
public $helpUrlArray = array(
'dk' => 'http://www.typo3.com/man_dk/',
);
var $debugKey = FALSE; // If true, will show the key/location of labels in the backend.
public $debugKey = false; // If true, will show the key/location of labels in the backend.
var $moduleLabels = Array(); // Can contain labels and image references from the backend modules. Relies on t3lib_loadmodules to initialize modules after a global instance of $LANG has been created.
public $moduleLabels = array(); // Can contain labels and image references from the backend modules. Relies on t3lib_loadmodules to initialize modules after a global instance of $LANG has been created.
// Internal
var $langSplitIndex=0; // Points to the position of the current language key as found in constant TYPO3_languages
var $LL_files_cache=array(); // Internal cache for read LL-files
var $LL_labels_cache=array(); // Internal cache for ll-labels (filled as labels are requested)
protected $langSplitIndex = 0; // Points to the position of the current language key as found in constant TYPO3_languages
protected $LL_files_cache = array(); // Internal cache for read LL-files
protected $LL_labels_cache = array(); // Internal cache for ll-labels (filled as labels are requested)
/**
* instance of the "t3lib_cs" class. May be used by any application.
......
* Initializes the backend language.
* This is for example done in typo3/template.php with lines like these:
*
* require (PATH_typo3.'sysext/lang/lang.php');
* require (PATH_typo3 . 'sysext/lang/lang.php');
* $LANG = t3lib_div::makeInstance('language');
* $LANG->init($BE_USER->uc['lang']);
*
......
* @param string IGNORE. Not used.
* @return void
*/
function init($lang,$altPath='') {
function init($lang, $altPath = '') {
// Initialize the conversion object:
$this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
$this->charSetArray = $this->csConvObj->charSetArray;
// Internally setting the list of TYPO3 backend languages.
$this->langSplit=TYPO3_languages;
$this->langSplit = TYPO3_languages;
// Finding the requested language in this list based on the $lang key being inputted to this function.
$ls = explode('|',$this->langSplit);
while(list($i,$v)=each($ls)) {
if ($v==$lang) { // Language is found. Configure it:
$this->langSplitIndex=$i; // The index of the language as found in the TYPO3_languages list
$ls = explode('|', $this->langSplit);
foreach ($ls as $i => $v) {
if ($v == $lang) { // Language is found. Configure it:
$this->langSplitIndex = $i; // The index of the language as found in the TYPO3_languages list
$this->lang = $lang; // The current language key
if ($this->helpUrlArray[$this->lang]) $this->typo3_help_url=$this->helpUrlArray[$this->lang]; // The help URL if different from the default.
if ($this->charSetArray[$this->lang]) $this->charSet=$this->charSetArray[$this->lang]; // The charset if different from the default.
if ($this->helpUrlArray[$this->lang]) $this->typo3_help_url = $this->helpUrlArray[$this->lang]; // The help URL if different from the default.
if ($this->charSetArray[$this->lang]) $this->charSet = $this->charSetArray[$this->lang]; // The charset if different from the default.
}
}
......
}
// If a forced charset is used and different from the charset otherwise used:
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']!=$this->charSet) {
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != $this->charSet) {
// Set the forced charset:
$this->charSet = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
if ($this->charSet!='utf-8' && !$this->csConvObj->initCharset($this->charSet)) {
t3lib_BEfunc::typo3PrintError ('The forced character set "'.$this->charSet.'" was not found in t3lib/csconvtbl/','Forced charset not found');
if ($this->charSet != 'utf-8' && !$this->csConvObj->initCharset($this->charSet)) {
t3lib_BEfunc::typo3PrintError ('The forced character set "' . $this->charSet . '" was not found in t3lib/csconvtbl/', 'Forced charset not found');
exit;
}
}
......
* @return void
* @see t3lib_loadModules
*/
function addModuleLabels($arr,$prefix) {
function addModuleLabels($arr, $prefix) {
if (is_array($arr)) {
reset($arr);
while(list($k,$larr)=each($arr)) {
foreach ($arr as $k => $larr) {
if (!isset($this->moduleLabels[$k])) {
$this->moduleLabels[$k]=array();
$this->moduleLabels[$k] = array();
}
if (is_array($larr)) {
reset($larr);
while(list($l,$v)=each($larr)) {
$this->moduleLabels[$k][$prefix.$l]=$v;
foreach ($larr as $l => $v) {
$this->moduleLabels[$k][$prefix . $l] = $v;
}
}
}
......
* @return string The processed string
* @see init()
*/
function hscAndCharConv($lStr,$hsc) {
function hscAndCharConv($lStr, $hsc) {
$lStr = $hsc ? htmlspecialchars($lStr) : $lStr;
// labels returned from a locallang file used to be in the language of the charset. Since TYPO3 4.1 they are always in the charset of the BE.
......
*/
function makeEntities($str) {
// Convert string to UTF-8:
if ($this->charSet!='utf-8') $str = $this->csConvObj->utf8_encode($str,$this->charSet);
if ($this->charSet != 'utf-8') $str = $this->csConvObj->utf8_encode($str, $this->charSet);
// Convert string back again, but using the full entity conversion:
$str = $this->csConvObj->utf8_to_entities($str);
......
function JScharCode($str) {
// Convert string to UTF-8:
if ($this->charSet!='utf-8') $str = $this->csConvObj->utf8_encode($str,$this->charSet);
if ($this->charSet != 'utf-8') $str = $this->csConvObj->utf8_encode($str, $this->charSet);
// Convert the UTF-8 string into a array of char numbers:
$nArr = $this->csConvObj->utf8_to_numberarray($str);
......
// Convert the UTF-8 string into a array of char numbers:
$nArr = $this->csConvObj->utf8_to_numberarray($str);
return 'String.fromCharCode('.implode(',',$nArr).')';
return 'String.fromCharCode(' . implode(',', $nArr) . ')';
}
/**
......
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function getLL($index,$hsc=0) {
function getLL($index, $hsc = 0) {
// Get Local Language
if (strcmp($GLOBALS['LOCAL_LANG'][$this->lang][$index],'')) {
if (strcmp($GLOBALS['LOCAL_LANG'][$this->lang][$index], '')) {
$output = $this->hscAndCharConv($GLOBALS['LOCAL_LANG'][$this->lang][$index], $hsc); // Returns local label if not blank.
} else {
$output = $this->hscAndCharConv($GLOBALS['LOCAL_LANG']['default'][$index], $hsc); // Returns default label
......
} else {
$output = $this->hscAndCharConv($GLOBALS['LOCAL_LANG']['default'][$index], $hsc); // Returns default label
}
return $output.($this->debugKey ? ' ['.$index.']':'');
return $output . ($this->debugKey ? ' [' . $index . ']':'');
}
/**
......
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function getLLL($index,$LOCAL_LANG,$hsc=0) {
function getLLL($index, $LOCAL_LANG, $hsc = 0) {
// Get Local Language
if (strcmp($LOCAL_LANG[$this->lang][$index],'')) {
if (strcmp($LOCAL_LANG[$this->lang][$index], '')) {
$output = $this->hscAndCharConv($LOCAL_LANG[$this->lang][$index], $hsc); // Returns local label if not blank.
} else {
$output = $this->hscAndCharConv($LOCAL_LANG['default'][$index], $hsc); // Returns default label
......
} else {
$output = $this->hscAndCharConv($LOCAL_LANG['default'][$index], $hsc); // Returns default label
}
return $output.($this->debugKey ? ' ['.$index.']':'');
return $output . ($this->debugKey ? ' [' . $index . ']':'');
}
/**
......
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function sL($input,$hsc=0) {
if (strcmp(substr($input,0,4),'LLL:')) { // Using obsolete 'language-splitted' labels:
$t = explode('|',$input);
function sL($input, $hsc = 0) {
if (strcmp(substr($input, 0, 4), 'LLL:')) { // Using obsolete 'language-splitted' labels:
$t = explode('|', $input);
$out = $t[$this->langSplitIndex] ? $t[$this->langSplitIndex] : $t[0];
return $this->hscAndCharConv($out, $hsc);
} else { // LOCAL_LANG:
......
return $this->hscAndCharConv($out, $hsc);
} else { // LOCAL_LANG:
if (!isset($this->LL_labels_cache[$this->lang][$input])) { // If cached label
$restStr = trim(substr($input,4));
$extPrfx='';
if (!strcmp(substr($restStr,0,4),'EXT:')) { // ll-file refered to is found in an extension.
$restStr = trim(substr($restStr,4));
$extPrfx='EXT:';
$restStr = trim(substr($input, 4));
$extPrfx = '';
if (!strcmp(substr($restStr, 0, 4), 'EXT:')) { // ll-file refered to is found in an extension.
$restStr = trim(substr($restStr, 4));
$extPrfx = 'EXT:';
}
$parts = explode(':',$restStr);
$parts[0]=$extPrfx.$parts[0];
$parts = explode(':', $restStr);
$parts[0] = $extPrfx . $parts[0];
if (!isset($this->LL_files_cache[$parts[0]])) { // Getting data if not cached
$this->LL_files_cache[$parts[0]] = $this->readLLfile($parts[0]);
......
// If the current language is found in another file, load that as well:
$lFileRef = $this->localizedFileRef($parts[0]);
if ($lFileRef && is_string($this->LL_files_cache[$parts[0]][$this->lang]) && $this->LL_files_cache[$parts[0]][$this->lang]=='EXT') {
if ($lFileRef && is_string($this->LL_files_cache[$parts[0]][$this->lang]) && $this->LL_files_cache[$parts[0]][$this->lang] == 'EXT') {
$tempLL = $this->readLLfile($lFileRef);
$this->LL_files_cache[$parts[0]][$this->lang] = $tempLL[$this->lang];
}
......
// Overriding file?
if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]])) {
$ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]]);
$this->LL_files_cache[$parts[0]] = t3lib_div::array_merge_recursive_overrule($this->LL_files_cache[$parts[0]],$ORarray);
$this->LL_files_cache[$parts[0]] = t3lib_div::array_merge_recursive_overrule($this->LL_files_cache[$parts[0]], $ORarray);
}
}
$this->LL_labels_cache[$this->lang][$input] = $this->getLLL($parts[1],$this->LL_files_cache[$parts[0]]);
$this->LL_labels_cache[$this->lang][$input] = $this->getLLL($parts[1], $this->LL_files_cache[$parts[0]]);
}
$output = $hsc ? t3lib_div::deHSCentities(htmlspecialchars($this->LL_labels_cache[$this->lang][$input])) : $this->LL_labels_cache[$this->lang][$input]; // For the cached output charset conversion has already happend! So perform HSC right here.
return $output.($this->debugKey ? ' ['.$input.']':'');
return $output . ($this->debugKey ? ' [' . $input . ']':'');
}
}
......
* @return void
*/
function loadSingleTableDescription($table) {
global $TCA_DESCR;
if (is_array($TCA_DESCR[$table])
&& !isset($TCA_DESCR[$table]['columns'])
&& is_array($TCA_DESCR[$table]['refs'])) { // First the 'table' cannot already be loaded in [columns] and secondly there must be a references to locallang files available in [refs]
if (is_array($GLOBALS['TCA_DESCR'][$table])
&& !isset($GLOBALS['TCA_DESCR'][$table]['columns'])
&& is_array($GLOBALS['TCA_DESCR'][$table]['refs'])) { // First the 'table' cannot already be loaded in [columns] and secondly there must be a references to locallang files available in [refs]
// Init $TCA_DESCR for $table-key
$TCA_DESCR[$table]['columns']=array();
$GLOBALS['TCA_DESCR'][$table]['columns'] = array();
// Get local-lang for each file in $TCA_DESCR[$table]['refs'] as they are ordered.
foreach ($TCA_DESCR[$table]['refs'] as $llfile) {
$LOCAL_LANG = $this->includeLLFile($llfile,0,1);
foreach ($GLOBALS['TCA_DESCR'][$table]['refs'] as $llfile) {
$LOCAL_LANG = $this->includeLLFile($llfile, 0, 1);
// Traverse all keys
if (is_array($LOCAL_LANG['default'])) {
......
// 0 => fieldname,
// 1 => type from (alttitle,description,details,syntax,image_descr,image,seeAlso),
// 2 => special instruction, see switch construct
$kParts = explode('.',$lkey);
$kParts = explode('.', $lkey);
// Detecting 'hidden' labels, converting to normal fieldname
if ($kParts[0]=='_') $kParts[0]='';
if (substr($kParts[0],0,1)=='_') { $kParts[0] = substr($kParts[0],1); }
if ($kParts[0] == '_') $kParts[0] = '';
if (substr($kParts[0], 0, 1) == '_') { $kParts[0] = substr($kParts[0], 1); }
// Add label:
switch((string)$kParts[2]) {
......
// Add label:
switch((string)$kParts[2]) {
case '+': // adding
$TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]].= chr(10).$lVal;
$GLOBALS['TCA_DESCR'][$table]['columns'][$kParts[0]][$kParts[1]] .= chr(10) . $lVal;
break;
default: // Substituting:
$TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]] = $lVal;
break;
$GLOBALS['TCA_DESCR'][$table]['columns'][$kParts[0]][$kParts[1]] = $lVal;
}
}
}
......
/**
* Includes locallang file (and possibly additional localized version if configured for)
* Read language labels will be merged with $LOCAL_LANG (if $setGlobal=1).
* Read language labels will be merged with $LOCAL_LANG (if $setGlobal = true).
*
* @param string $fileRef is a file-reference (see t3lib_div::getFileAbsFileName)
* @param boolean Setting in global variable $LOCAL_LANG (or returning the variable)
* @param boolean If $mergeLocalOntoDefault is set the local part of the $LOCAL_LANG array is merged onto the default part (if the local part exists) and the local part is unset.
* @return mixed If $setGlobal is true the LL-files will set the $LOCAL_LANG in the global scope. Otherwise the $LOCAL_LANG array is returned from function
*/
function includeLLFile($fileRef,$setGlobal=1,$mergeLocalOntoDefault=0) {
function includeLLFile($fileRef, $setGlobal = 1, $mergeLocalOntoDefault = 0) {
// Configure for global flag:
if ($setGlobal) {
global $LOCAL_LANG;
......
if (count($llang)) {
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule((array)$LOCAL_LANG,$llang);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule((array)$LOCAL_LANG, $llang);
// Localized addition?
$lFileRef = $this->localizedFileRef($fileRef);
if ($lFileRef && (string)$LOCAL_LANG[$this->lang]=='EXT') {
if ($lFileRef && (string)$LOCAL_LANG[$this->lang] == 'EXT') {
$llang = $this->readLLfile($lFileRef);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$llang);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG, $llang);
}
// Overriding file?
......
// Overriding file?
if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef])) {
$ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef]);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$ORarray);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG, $ORarray);
}
// Merge local onto default:
if ($mergeLocalOntoDefault && strcmp($this->lang,'default') && is_array($LOCAL_LANG[$this->lang]) && is_array($LOCAL_LANG['default'])) {
$LOCAL_LANG['default'] = array_merge($LOCAL_LANG['default'],$LOCAL_LANG[$this->lang]); // array_merge can be used so far the keys are not numeric - which we assume they are not...
if ($mergeLocalOntoDefault && strcmp($this->lang, 'default') && is_array($LOCAL_LANG[$this->lang]) && is_array($LOCAL_LANG['default'])) {
$LOCAL_LANG['default'] = array_merge($LOCAL_LANG['default'], $LOCAL_LANG[$this->lang]); // array_merge can be used so far the keys are not numeric - which we assume they are not...
unset($LOCAL_LANG[$this->lang]);
}
}
......
* @return string Input filename with a '.[lang-key].php' ending added if $this->lang is not 'default'
*/
function localizedFileRef($fileRef) {
if ($this->lang!='default' && substr($fileRef,-4)=='.php') {
return substr($fileRef,0,-4).'.'.$this->lang.'.php';
if ($this->lang != 'default' && substr($fileRef, -4) == '.php') {
return substr($fileRef, 0, -4) . '.' . $this->lang . '.php';
}
}
}
    (1-1/1)