Bug #29386 » 29386_v1.diff
typo3/sysext/lang/lang.php | ||
---|---|---|
public $parserFactory;
|
||
/**
|
||
* @var array
|
||
*/
|
||
protected $languageDependencies = array();
|
||
/**
|
||
* Initializes the backend language.
|
||
* This is for example done in typo3/template.php with lines like these:
|
||
*
|
||
... | ... | |
// The charset if different from the default.
|
||
$this->charSet = $this->charSetArray[$this->lang];
|
||
}
|
||
$this->languageDependencies[] = $this->lang;
|
||
foreach ($locales->getLocaleDependencies($this->lang) as $language) {
|
||
$this->languageDependencies[] = $language;
|
||
}
|
||
}
|
||
// Always fallback to 'default' as last resort
|
||
$this->languageDependencies[] = 'default';
|
||
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lang']['debug']) {
|
||
$this->debugKey = TRUE;
|
||
}
|
||
... | ... | |
* @access public
|
||
*/
|
||
public function getLL($index, $hsc = FALSE) {
|
||
// Get Local Language
|
||
if (isset($GLOBALS['LOCAL_LANG'][$this->lang][$index][0]['target'])) {
|
||
$output = $GLOBALS['LOCAL_LANG'][$this->lang][$index][0]['target'];
|
||
} else {
|
||
$output = $GLOBALS['LOCAL_LANG']['default'][$index][0]['target'];
|
||
$output = '';
|
||
foreach ($this->languageDependencies as $language) {
|
||
if (isset($GLOBALS['LOCAL_LANG'][$language][$index][0]['target'])) {
|
||
$output = $GLOBALS['LOCAL_LANG'][$language][$index][0]['target'];
|
||
break;
|
||
}
|
||
}
|
||
if ($hsc) {
|
||
$output = htmlspecialchars($output);
|
||
... | ... | |
* @access public
|
||
*/
|
||
public function getLLL($index, $localLanguage, $hsc = FALSE) {
|
||
// Get Local Language. Special handling for all extensions that
|
||
// read PHP LL files and pass arrays here directly.
|
||
$value = is_string($localLanguage[$this->lang][$index]) ? $localLanguage[$this->lang][$index] : $localLanguage[$this->lang][$index][0]['target'];
|
||
// Fallback to default language
|
||
if (trim($value) === '') {
|
||
$value = is_string($localLanguage['default'][$index]) ? $localLanguage['default'][$index] : $localLanguage['default'][$index][0]['target'];
|
||
// Special handling for all extensions that read PHP LL files and pass arrays here directly
|
||
$value = '';
|
||
foreach ($this->languageDependencies as $language) {
|
||
$value = is_string($localLanguage[$language][$index]) ? $localLanguage[$language][$index] : $localLanguage[$language][$index][0]['target'];
|
||
if (trim($value) !== '') {
|
||
break;
|
||
}
|
||
}
|
||
if ($hsc) {
|
||
... | ... | |
* @access public
|
||
*/
|
||
public function sL($input, $hsc = FALSE) {
|
||
// If cached label
|
||
if (!isset($this->LL_labels_cache[$this->lang][$input]) && substr($input, 0, 4) === 'LLL:') {
|
||
$restStr = trim(substr($input, 4));
|
||
$extPrfx = '';
|
||
// ll-file refered to is found in an extension.
|
||
if (!strcmp(substr($restStr, 0, 4), 'EXT:')) {
|
||
$restStr = trim(substr($restStr, 4));
|
||
$extPrfx = 'EXT:';
|
||
}
|
||
$parts = explode(':', $restStr);
|
||
$parts[0] = $extPrfx . $parts[0];
|
||
// Getting data if not cached
|
||
if (!isset($this->LL_files_cache[$parts[0]])) {
|
||
$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') {
|
||
$tempLL = $this->readLLfile($lFileRef);
|
||
$this->LL_files_cache[$parts[0]][$this->lang] = $tempLL[$this->lang];
|
||
$languages = $this->languageDependencies;
|
||
// We don't need to fall back to English here as it is already handled by readLL()
|
||
if ($this->lang !== 'default') {
|
||
array_pop($languages);
|
||
}
|
||
// Make sure data is cached for all languages
|
||
foreach ($languages as $language) {
|
||
if (!isset($this->LL_labels_cache[$language][$input]) && substr($input, 0, 4) === 'LLL:') {
|
||
$restStr = trim(substr($input, 4));
|
||
$extPrfx = '';
|
||
// ll-file referred to is found in an extension.
|
||
if (!strcmp(substr($restStr, 0, 4), 'EXT:')) {
|
||
$restStr = trim(substr($restStr, 4));
|
||
$extPrfx = 'EXT:';
|
||
}
|
||
$parts = explode(':', $restStr);
|
||
$parts[0] = $extPrfx . $parts[0];
|
||
// Getting data if not cached
|
||
if (!isset($this->LL_files_cache[$parts[0]])) {
|
||
$this->LL_files_cache[$parts[0]] = array();
|
||
}
|
||
if (!isset($this->LL_files_cache[$parts[0]][$language])) {
|
||
$tempLL = $this->readLLfile($parts[0], $language);
|
||
$this->LL_files_cache[$parts[0]] = array_merge_recursive($this->LL_files_cache[$parts[0]], $tempLL);
|
||
// 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]][$language])
|
||
&& $this->LL_files_cache[$parts[0]][$language] === 'EXT') {
|
||
$tempLL = $this->readLLfile($lFileRef, $language);
|
||
$this->LL_files_cache[$parts[0]][$language] = $tempLL[$language];
|
||
}
|
||
}
|
||
$this->LL_labels_cache[$language][$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]]);
|
||
}
|
||
// For the cached output charset conversion has already happened!
|
||
// So perform HSC right here.
|
||
// Fall back to other languages has been cached, meaning
|
||
// we will have a proper label if key $input exists at all!
|
||
if (isset($this->LL_labels_cache[$this->lang][$input])) {
|
||
$output = $this->LL_labels_cache[$this->lang][$input];
|
||
} else {
|
||
... | ... | |
$output = $input;
|
||
}
|
||
// For the cached output charset conversion has already happened!
|
||
// So perform HSC right here.
|
||
if ($hsc) {
|
||
$output = t3lib_div::deHSCentities(htmlspecialchars($output));
|
||
}
|
||
... | ... | |
/**
|
||
* Includes a locallang file and returns the $LOCAL_LANG array found inside.
|
||
*
|
||
* @param string $fileRef Input is a file-reference (see t3lib_div::getFileAbsFileName) which, if exists, is included. That file is expected to be a 'local_lang' file containing a $LOCAL_LANG array.
|
||
* @return array Value of $LOCAL_LANG found in the included file. If that array is found it's returned. Otherwise an empty array
|
||
* @access private
|
||
* @param string $fileRef Input is a file-reference (see t3lib_div::getFileAbsFileName) which, if exists, is included. That file is expected to be a 'local_lang' file containing a $LOCAL_LANG array.
|
||
* @param string $language Optional language to use. Defaults to $this->lang
|
||
* @return array Value of $LOCAL_LANG found in the included file. If that array is found it's returned. Otherwise an empty array
|
||
*/
|
||
protected function readLLfile($fileRef) {
|
||
return t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet);
|
||
protected function readLLfile($fileRef, $language = '') {
|
||
return t3lib_div::readLLfile($fileRef, $language ?: $this->lang, $this->charSet);
|
||
}
|
||
/**
|