[BUGFIX] LLXML Parser does not support localized label in the main LLXML
authorDominique Feyer <dominique.feyer@reelpeek.net>
Thu, 7 Jul 2011 22:21:46 +0000 (00:21 +0200)
committerXavier Perseguers <typo3@perseguers.ch>
Fri, 8 Jul 2011 10:16:26 +0000 (12:16 +0200)
Many extension use the main LLXML file to provide default language and
others languages (fr, de, ...). The parser must support that.

This patch add this support. The priority is always given to the
language pack found in typo3conf/l10n. If a language pack is found
the localized label in the main LLXML file are not parsed.

Change-Id: I27e2ba03679ed4cf00c23c6140d243cf6aba2256
Resolves: #27972
Reviewed-on: http://review.typo3.org/3119
Reviewed-by: Björn Pedersen
Tested-by: Björn Pedersen
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/lang/classes/parser/class.tx_lang_parser_llxml.php

index c003b13..699071f 100644 (file)
@@ -81,13 +81,32 @@ class tx_lang_parser_Llxml extends tx_lang_parser_AbstractXml {
         * @return array
         */
        protected function _doParsingFromRoot(SimpleXMLElement $root, $element) {
-               $parsedData = array();
                $bodyOfFileTag = $root->data->languageKey;
 
+               $parsedData = $this->_getParsedData($bodyOfFileTag, $element);
+
+                       // Check if the source llxml file contains localized records
+               $localizedBodyOfFileTag = $root->data->xpath("languageKey[@index='" . $this->languageKey . "']");
+               if ($element === 'target' && isset($localizedBodyOfFileTag[0]) && $localizedBodyOfFileTag[0] instanceof SimpleXMLElement) {
+                       $parsedData = array_merge($parsedData, $this->_getParsedData($localizedBodyOfFileTag[0], $element));
+               }
+
+               return $parsedData;
+       }
+
+       /**
+        * Parse the given language key tag
+        *
+        * @param SimpleXMLElement $bodyOfFileTag
+        * @param string $element
+        * @return array
+        */
+       protected function _getParsedData(SimpleXMLElement $bodyOfFileTag, $element) {
+               $parsedData = array();
+
                foreach ($bodyOfFileTag->children() as $translationElement) {
                        if ($translationElement->getName() === 'label') {
                                        // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
-
                                $parsedData[(string)$translationElement['index']][0] = array(
                                        $element => (string)$translationElement,
                                );