Project

General

Profile

Feature #23561 » 0015741_v4.patch

Administrator Admin, 2010-09-19 15:37

View differences:

tests/t3lib/t3lib_pagerendererTest.php (Arbeitskopie)
$this->assertContains($testPrefix . '_\\u00d8', $out);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLablesPassed() {
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml',
'de'
);
$inlineLanguageLabels = $this->fixture->getInlineLanguageLabels();
$this->assertTrue(isset($inlineLanguageLabels['labels.beUser']));
$this->assertTrue(isset($inlineLanguageLabels['labels.feUser']));
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLablesEmptyOnNonExistingFile() {
$this->fixture->addInlineLanguageLabelFile(
'',
'de'
);
$inlineLanguageLabels = $this->fixture->getInlineLanguageLabels();
$this->assertEquals(array(), $inlineLanguageLabels);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLablesSelected() {
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml',
'de',
'labels.'
);
$inlineLanguageLabels = $this->fixture->getInlineLanguageLabels();
$this->assertTrue(isset($inlineLanguageLabels['beUser']));
$this->assertTrue(isset($inlineLanguageLabels['feUser']));
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLablesSelectedAndStripped() {
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml',
'de',
'labels.',
'lock'
);
$inlineLanguageLabels = $this->fixture->getInlineLanguageLabels();
$this->assertTrue(isset($inlineLanguageLabels['edRecord']));
$this->assertTrue(isset($inlineLanguageLabels['edRecord_content']));
$this->assertTrue(isset($inlineLanguageLabels['edRecordUser']));
}
}
?>
t3lib/class.t3lib_pagerenderer.php (Arbeitskopie)
}
/**
* Gets labels to be used in JavaScript fetched from a locallang file.
*
* @param string Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a 'locallang.xml' file containing a valid XML TYPO3 language structure.
* @param string Language key
* @param string $selectionPrefix: Prefix to select the correct labels (default: '')
* @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
* @param string Character set (option); if not set, determined by the language key
* @param integer Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
* @return void
*/
public function addInlineLanguageLabelFile($fileRef, $langKey, $selectionPrefix = '', $stripFromSelectionName = '', $charset = '', $errorMode = 0) {
$labelsFromFile = array();
$allLabels = t3lib_div::readLLfile($fileRef, $langKey, $charset, $errorMode);
// Regular expression to strip the selection prefix and possibly something from the label name:
$labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
if ($allLabels !== FALSE) {
// Merge language specific translations:
if ($langKey !== 'default' && isset($allLabels[$langKey])) {
$labels = array_merge($allLabels['default'], $allLabels[$langKey]);
} else {
$labels = $allLabels['default'];
}
// Iterate through all locallang labels:
foreach ($labels as $label => $value) {
if ($selectionPrefix === '') {
$labelsFromFile[$label] = $value;
} elseif (strpos($label, $selectionPrefix) === 0) {
$key = preg_replace($labelPattern, '', $label);
$labelsFromFile[$key] = $value;
}
}
$this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
}
}
/**
* Gets the inline language lablels.
*
* @return array The inline language lables
*/
public function getInlineLanguageLabels() {
return $this->inlineLanguageLabels;
}
/**
* Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
* The label can be used in scripts with TYPO3.setting.<key>
* Need extJs loaded
(2-2/3)