Index: tests/t3lib/t3lib_pagerendererTest.php =================================================================== --- tests/t3lib/t3lib_pagerendererTest.php (Revision 8820) +++ tests/t3lib/t3lib_pagerendererTest.php (Arbeitskopie) @@ -55,7 +55,7 @@ public function setUp() { $this->fixture = new t3lib_PageRenderer(); - $this->fixture->setCharSet('utf-8'); + $this->fixture->setCharSet($GLOBALS['LANG']->charSet); } public function tearDown() { @@ -773,5 +773,85 @@ $this->assertContains($testPrefix . '_\\u00d8', $out); } + + /** + * Tests the addInlineLanguageLabelFile() method. + * + * @test + * @expectedException RuntimeException + */ + public function areInlineLanguageLablesNotProcessable() { + $this->fixture->setLanguage(NULL); + $this->fixture->addInlineLanguageLabelFile( + 'EXT:lang/locallang_core.xml' + ); + } + + /** + * Tests the addInlineLanguageLabelFile() method. + * + * @test + */ + public function areInlineLanguageLablesPassed() { + $this->fixture->setLanguage($GLOBALS['LANG']->lang); + $this->fixture->addInlineLanguageLabelFile( + 'EXT:lang/locallang_core.xml' + ); + + $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->setLanguage($GLOBALS['LANG']->lang); + $this->fixture->addInlineLanguageLabelFile( + '' + ); + + $inlineLanguageLabels = $this->fixture->getInlineLanguageLabels(); + $this->assertEquals(array(), $inlineLanguageLabels); + } + + /** + * Tests the addInlineLanguageLabelFile() method. + * + * @test + */ + public function areInlineLanguageLablesSelected() { + $this->fixture->setLanguage($GLOBALS['LANG']->lang); + $this->fixture->addInlineLanguageLabelFile( + 'EXT:lang/locallang_core.xml', + '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->setLanguage($GLOBALS['LANG']->lang); + $this->fixture->addInlineLanguageLabelFile( + 'EXT:lang/locallang_core.xml', + 'labels.', + 'lock' + ); + + $inlineLanguageLabels = $this->fixture->getInlineLanguageLabels(); + $this->assertTrue(isset($inlineLanguageLabels['edRecord'])); + $this->assertTrue(isset($inlineLanguageLabels['edRecord_content'])); + $this->assertTrue(isset($inlineLanguageLabels['edRecordUser'])); + } } ?> \ No newline at end of file Index: t3lib/class.t3lib_pagerenderer.php =================================================================== --- t3lib/class.t3lib_pagerenderer.php (Revision 8820) +++ t3lib/class.t3lib_pagerenderer.php (Arbeitskopie) @@ -1102,6 +1102,58 @@ } /** + * 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 $selectionPrefix: Prefix to select the correct labels (default: '') + * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '') + * @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, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) { + if (!isset($this->lang) || !isset($this->charSet)) { + throw new RuntimeException('Language and character encoding are not set.', 1284906026); + } + + $labelsFromFile = array(); + $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->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 ($this->lang !== 'default' && isset($allLabels[$this->lang])) { + $labels = array_merge($allLabels['default'], $allLabels[$this->lang]); + } 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. * Need extJs loaded