[BUGFIX] Regression in language handling
authorNils Seinschedt <n.seinschedt@neusta.de>
Mon, 16 Jan 2012 18:09:46 +0000 (19:09 +0100)
committerXavier Perseguers <xavier@typo3.org>
Sun, 22 Jan 2012 21:45:06 +0000 (22:45 +0100)
If you request a translated string in a
language where no translation is available
you used to get the default language
labels in the [target] array attribute of
the LOCAL_LANG array for that language.
After the fix of #32573 you only get the
[source] element filled. Which breaks
extensions (like extbase/fluid) that rely on
always having the [target] attribute filled.

Change-Id: I750cd3a7385ed0ff0449f0478a1170251abd41f8
Resolves: #33227
Releases: 4.6, 4.7
Reviewed-on: http://review.typo3.org/8611
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/l10n/parser/class.t3lib_l10n_parser_llxml.php
tests/t3lib/l10n/parser/class.t3lib_l10n_parser_llxmlTest.php
tests/t3lib/l10n/parser/fixtures/locallangOnlyDefaultLanguage.xml [new file with mode: 0644]

index d3e7de0..9dcf937 100644 (file)
@@ -85,9 +85,6 @@ class t3lib_l10n_parser_Llxml extends t3lib_l10n_parser_AbstractXml {
 
                        // Check if the source llxml file contains localized records
                $localizedBodyOfFileTag = $root->data->xpath("languageKey[@index='" . $this->languageKey . "']");
-               if ($element === 'target' && empty($localizedBodyOfFileTag)) {
-                       return array();
-               }
 
                $parsedData = $this->getParsedDataForElement($bodyOfFileTag, $element);
                if ($element === 'target' && isset($localizedBodyOfFileTag[0]) && $localizedBodyOfFileTag[0] instanceof SimpleXMLElement) {
index d21af21..04b8e02 100644 (file)
@@ -62,6 +62,7 @@ class t3lib_l10n_parser_llxmlTest extends tx_phpunit_testcase {
                $this->llxmlFileNames = array(
                        'locallang' => PATH_site . 'typo3_src/tests/t3lib/l10n/parser/fixtures/locallang.xml',
                        'locallang_override' => PATH_site . 'typo3_src/tests/t3lib/l10n/parser/fixtures/locallang_override.xml',
+                       'locallangOnlyDefaultLanguage' =>  PATH_site . 'typo3_src/tests/t3lib/l10n/parser/fixtures/locallangOnlyDefaultLanguage.xml',
                );
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xml';
                t3lib_div::makeInstance('t3lib_l10n_Store')->initialize();
@@ -123,6 +124,23 @@ class t3lib_l10n_parser_llxmlTest extends tx_phpunit_testcase {
        /**
         * @test
         */
+       public function canParseLlxmlInFrenchAndReturnsDefaultLabelsIfNoTranslationIsFound() {
+               $LOCAL_LANG = $this->parser->getParsedData($this->llxmlFileNames['locallangOnlyDefaultLanguage'], 'fr');
+
+               $expectedLabels = array(
+                       'label1' => 'This is label #1',
+                       'label2' => 'This is label #2',
+                       'label3' => 'This is label #3',
+               );
+
+               foreach ($expectedLabels as $key => $expectedLabel) {
+                       $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
+               }
+       }
+
+       /**
+        * @test
+        */
        public function canOverrideLlxml() {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'][$this->llxmlFileNames['locallang']][] = $this->llxmlFileNames['locallang_override'];
 
diff --git a/tests/t3lib/l10n/parser/fixtures/locallangOnlyDefaultLanguage.xml b/tests/t3lib/l10n/parser/fixtures/locallangOnlyDefaultLanguage.xml
new file mode 100644 (file)
index 0000000..8a78841
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<T3locallang>
+       <meta type="array">
+               <description>Fixture labels for unit tests.</description>
+               <type>module</type>
+       </meta>
+       <data type="array">
+               <languageKey index="default" type="array">
+                       <label index="label1">This is label #1</label>
+                       <label index="label2">This is label #2</label>
+                       <label index="label3">This is label #3</label>
+               </languageKey>
+       </data>
+</T3locallang>
\ No newline at end of file