[TASK] Move XLIFF handling to t3lib
authorXavier Perseguers <typo3@perseguers.ch>
Thu, 7 Jul 2011 23:29:41 +0000 (01:29 +0200)
committerXavier Perseguers <typo3@perseguers.ch>
Mon, 11 Jul 2011 14:14:45 +0000 (16:14 +0200)
All XLIFF code should better be located within t3lib.

Change-Id: I2bad66f9e2c92015e9aab4a06e8c92e96762ab9a
Resolves: #28055
Reviewed-on: http://review.typo3.org/3217
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
28 files changed:
t3lib/class.t3lib_div.php
t3lib/config_default.php
t3lib/core_autoload.php
t3lib/l10n/class.t3lib_l10n_factory.php [new file with mode: 0644]
t3lib/l10n/class.t3lib_l10n_store.php [new file with mode: 0644]
t3lib/l10n/exception/class.t3lib_l10n_exception_filenotfound.php [new file with mode: 0644]
t3lib/l10n/exception/class.t3lib_l10n_exception_invalidparser.php [new file with mode: 0644]
t3lib/l10n/exception/class.t3lib_l10n_exception_invalidxmlfile.php [new file with mode: 0644]
t3lib/l10n/interfaces/interface.t3lib_l10n_parser.php [new file with mode: 0644]
t3lib/l10n/parser/class.t3lib_l10n_parser_abstractxml.php [new file with mode: 0644]
t3lib/l10n/parser/class.t3lib_l10n_parser_llphp.php [new file with mode: 0644]
t3lib/l10n/parser/class.t3lib_l10n_parser_llxml.php [new file with mode: 0644]
t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php [new file with mode: 0644]
tests/t3lib/class.t3lib_divTest.php
typo3/sysext/lang/classes/class.tx_lang_factory.php [deleted file]
typo3/sysext/lang/classes/class.tx_lang_store.php [deleted file]
typo3/sysext/lang/classes/exception/class.tx_lang_exception_filenotfound.php [deleted file]
typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidparser.php [deleted file]
typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidxmlfile.php [deleted file]
typo3/sysext/lang/classes/interfaces/interface.tx_lang_parser.php [deleted file]
typo3/sysext/lang/classes/parser/class.tx_lang_parser_abstractxml.php [deleted file]
typo3/sysext/lang/classes/parser/class.tx_lang_parser_llphp.php [deleted file]
typo3/sysext/lang/classes/parser/class.tx_lang_parser_llxml.php [deleted file]
typo3/sysext/lang/classes/parser/class.tx_lang_parser_xliff.php [deleted file]
typo3/sysext/lang/ext_autoload.php [deleted file]
typo3/sysext/lang/ext_localconf.php
typo3/sysext/lang/hooks/clearcache/class.tx_lang_clearcache.php
typo3/sysext/lang/lang.php

index 97a29e6..d267b13 100644 (file)
@@ -4131,8 +4131,8 @@ final class t3lib_div {
         *                                               Otherwise an empty array and it is FALSE in error case.
         */
        public static function readLLfile($fileRef, $langKey, $charset = '', $errorMode = 0) {
-               /** @var $languageFactory tx_lang_Factory */
-               $languageFactory = t3lib_div::makeInstance('tx_lang_Factory');
+               /** @var $languageFactory t3lib_l10n_Factory */
+               $languageFactory = t3lib_div::makeInstance('t3lib_l10n_Factory');
                return $languageFactory->getParsedData($fileRef, $langKey, $charset, $errorMode);
        }
 
@@ -5638,4 +5638,4 @@ final class t3lib_div {
        }
 }
 
-?>
\ No newline at end of file
+?>
index c27e034..23d103a 100644 (file)
@@ -64,9 +64,9 @@ $TYPO3_CONF_VARS = array(
                                'priority' => 'xlf,xml,php'
                        ),
                        'parser' => array(
-                               'php' => 'tx_lang_parser_Llphp',
-                               'xml' => 'tx_lang_parser_Llxml',
-                               'xlf' => 'tx_lang_parser_Xliff',
+                               'php' => 't3lib_l10n_parser_Llphp',
+                               'xml' => 't3lib_l10n_parser_Llxml',
+                               'xlf' => 't3lib_l10n_parser_Xliff',
                        ),
                ),
                'sitename' => 'TYPO3',                                  // Name of the base-site. This title shows up in the root of the tree structure if you're an 'admin' backend user.
index c8689e7..390ddea 100644 (file)
@@ -38,6 +38,16 @@ $t3libClasses = array(
        't3lib_iconworks' => PATH_t3lib . 'class.t3lib_iconworks.php',
        't3lib_install' => PATH_t3lib . 'class.t3lib_install.php',
        't3lib_install_sql' => PATH_t3lib . 'class.t3lib_install_sql.php',
+       't3lib_l10n_factory' => PATH_t3lib . 'l10n/class.t3lib_l10n_factory.php',
+       't3lib_l10n_store' => PATH_t3lib . 'l10n/class.t3lib_l10n_store.php',
+       't3lib_l10n_exception_filenotfound' => PATH_t3lib . 'l10n/exception/class.t3lib_l10n_exception_filenotfound.php',
+       't3lib_l10n_exception_invalidparser' => PATH_t3lib . 'l10n/exception/class.t3lib_l10n_exception_invalidparser.php',
+       't3lib_l10n_exception_invalidxmlfile' => PATH_t3lib . 'l10n/exception/class.t3lib_l10n_exception_invalidxmlfile.php',
+       't3lib_l10n_parser' => PATH_t3lib . 'l10n/interfaces/interface.t3lib_l10n_parser.php',
+       't3lib_l10n_parser_abstractxml' => PATH_t3lib . 'l10n/parser/class.t3lib_l10n_parser_abstractxml.php',
+       't3lib_l10n_parser_llphp' => PATH_t3lib . 'l10n/parser/class.t3lib_l10n_parser_llphp.php',
+       't3lib_l10n_parser_llxml' => PATH_t3lib . 'l10n/parser/class.t3lib_l10n_parser_llxml.php',
+       't3lib_l10n_parser_xliff' => PATH_t3lib . 'l10n/parser/class.t3lib_l10n_parser_xliff.php',
        't3lib_loaddbgroup' => PATH_t3lib . 'class.t3lib_loaddbgroup.php',
        't3lib_loadmodules' => PATH_t3lib . 'class.t3lib_loadmodules.php',
        't3lib_lock' => PATH_t3lib . 'class.t3lib_lock.php',
diff --git a/t3lib/l10n/class.t3lib_l10n_factory.php b/t3lib/l10n/class.t3lib_l10n_factory.php
new file mode 100644 (file)
index 0000000..8864ebd
--- /dev/null
@@ -0,0 +1,181 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Provides a language parser factory.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_Factory implements t3lib_Singleton {
+
+       /**
+        * @var t3lib_cache_frontend_StringFrontend
+        */
+       protected $cacheInstance;
+
+       /**
+        * @var integer
+        */
+       protected $errorMode;
+
+       /**
+        * @var t3lib_l10n_Store
+        */
+       public $store;
+
+       /**
+        * Class constructor
+        */
+       public function __construct() {
+               $this->initialize();
+       }
+
+       protected function initialize() {
+               $this->store = t3lib_div::makeInstance('t3lib_l10n_Store');
+
+               $this->initializeCache();
+       }
+
+       /**
+        * Initialize cache instance to be ready to use
+        *
+        * @return void
+        */
+       protected function initializeCache() {
+               $this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('t3lib_l10n');
+       }
+
+       /**
+        * Returns parsed data from a given file and language key.
+        *
+        * @param string $fileReference Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a supported locallang file format
+        * @param string $languageKey Language key
+        * @param string $charset Character set (option); if not set, determined by the language key
+        * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
+        * @return array|bool
+        */
+       public function getParsedData($fileReference, $languageKey, $charset, $errorMode) {
+               try {
+                       $hash = md5($fileReference . $languageKey . $charset);
+                       $this->errorMode = $errorMode;
+
+                               // English is the default language
+                       $languageKey = ($languageKey === 'en') ? 'default' : $languageKey;
+
+                               // Check if the default language is processed before processing other language
+                       if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
+                               $this->getParsedData($fileReference, 'default', $charset, $this->errorMode);
+                       }
+
+                               // If the content is parsed (local cache), use it
+                       if ($this->store->hasData($fileReference, $languageKey)) {
+                               return $this->store->getData($fileReference);
+                       }
+
+                               // If the content is in cache (system cache), use it
+                       if ($this->cacheInstance->has($hash)) {
+                                       // Load data from the caching framework
+                               $this->store->setData($fileReference, $languageKey, $this->cacheInstance->get($hash));
+
+                               return $this->store->getData($fileReference, $languageKey);
+                       }
+
+                       $this->store->setConfiguration($fileReference, $languageKey, $charset);
+
+                       /** @var $parser t3lib_l10n_parser */
+                       $parser = $this->store->getParserInstance($fileReference);
+
+                               // Get parsed data
+                       $LOCAL_LANG = $parser->getParsedData(
+                               $this->store->getAbsoluteFileReference($fileReference),
+                               $languageKey,
+                               $charset
+                       );
+
+                               // Override localization
+                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
+                               $this->localizationOverride($fileReference, $languageKey, $charset, $errorMode, $LOCAL_LANG);
+                       }
+
+                               // Save parsed data in cache
+                       $this->store->setData(
+                               $fileReference,
+                               $languageKey,
+                               $LOCAL_LANG[$languageKey]
+                       );
+
+                               // Cache processed data
+                       $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
+               } catch (t3lib_l10n_exception_FileNotFound $exception) {
+                               // Source localization file not found
+                       $this->store->setData($fileReference, $languageKey, array());
+               }
+
+               return $this->store->getData($fileReference);
+       }
+
+       /**
+        * Override localization file
+        *
+        * This method merges the content of the override file with the default file
+        *
+        * @param string $fileReference
+        * @param string $languageKey
+        * @param string $charset
+        * @param integer $errorMode
+        * @param array $LOCAL_LANG
+        * @return void
+        */
+       protected function localizationOverride($fileReference, $languageKey, $charset, $errorMode, array &$LOCAL_LANG) {
+               $overrides = array();
+               $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
+
+               $locallangXMLOverride = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
+               foreach ($this->store->getSupportedExtensions() as $extension) {
+                       if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
+                               $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
+                       } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
+                               $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
+                       }
+               }
+
+               if (count($overrides) > 0) {
+                       foreach ($overrides as $overrideFile) {
+                               $languageOverrideFileName = t3lib_div::getFileAbsFileName($overrideFile);
+                               $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule(
+                                       $LOCAL_LANG,
+                                       $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode)
+                               );
+                       }
+               }
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/class.t3lib_l10n_store.php b/t3lib/l10n/class.t3lib_l10n_store.php
new file mode 100644 (file)
index 0000000..4cc4993
--- /dev/null
@@ -0,0 +1,258 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Language store.
+ *
+ * @package    Core
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dominique.feyer@reelpeek.net>
+ */
+class t3lib_l10n_Store implements t3lib_Singleton {
+
+       /**
+        * File extension supported by the localization parser
+        *
+        * @var array
+        */
+       protected $supportedExtensions;
+
+       /**
+        * Information about parsed file
+        *
+        * If data come from the cache, this array does not contain
+        * any information about this file
+        *
+        * @var array
+        */
+       protected $configuration;
+
+       /**
+        * Parsed localization file
+        *
+        * @var array
+        */
+       protected $data;
+
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               $this->initialize();
+       }
+
+       /**
+        * Initializes the current class.
+        *
+        * @return void
+        */
+       public function initialize() {
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
+                       $this->supportedExtensions = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
+               } else {
+                       $this->supportedExtensions = array('xlf', 'xml', 'php');
+               }
+       }
+
+       /**
+        * Checks if the store contains parsed data.
+        *
+        * @param string $fileReference File reference
+        * @param string $languageKey Valid language key
+        * @return bool
+        */
+       public function hasData($fileReference, $languageKey) {
+               if (isset($this->data[$fileReference][$languageKey]) && is_array($this->data[$fileReference][$languageKey])) {
+                       return TRUE;
+               }
+               return FALSE;
+       }
+
+       /**
+        * Retrieves data from the store.
+        *
+        * This method returns all parsed languages for the current file reference.
+        *
+        * @param string $fileReference File reference
+        * @return array
+        */
+       public function getData($fileReference) {
+               return $this->data[$fileReference];
+       }
+
+       /**
+        * Retrieves data from the store for a language.
+        *
+        * @param string $fileReference File reference
+        * @param string $languageKey Valid language key
+        * @return array
+        * @see self::getData()
+        */
+       public function getDataByLanguage($fileReference, $languageKey) {
+               return $this->data[$fileReference][$languageKey];
+       }
+
+       /**
+        * Sets data for a specific file reference and a language.
+        *
+        * @param string $fileReference File reference
+        * @param string $languageKey Valid language key
+        * @param $data
+        * @return t3lib_l10n_Store This instance to allow method chaining
+        */
+       public function setData($fileReference, $languageKey, $data) {
+               $this->data[$fileReference][$languageKey] = $data;
+               return $this;
+       }
+
+       /**
+        * Flushes data.
+        *
+        * @param string $fileReference
+        * @return t3lib_l10n_Store This instance to allow method chaining
+        */
+       public function flushData($fileReference) {
+               unset($this->data[$fileReference]);
+               return $this;
+       }
+
+       /**
+        * Checks file reference configuration (charset, extension, ...).
+        *
+        * @throws t3lib_l10n_exception_InvalidParser|t3lib_l10n_exception_FileNotFound
+        * @param string $fileReference File reference
+        * @param string $languageKey Valid language key
+        * @param string $charset Rendering charset
+        * @return t3lib_l10n_Store This instance to allow method chaining
+        */
+       public function setConfiguration($fileReference, $languageKey, $charset) {
+               $this->configuration[$fileReference] = array(
+                       'fileReference' => $fileReference,
+                       'fileExtension' => FALSE,
+                       'parserClass' => NULL,
+                       'languageKey' => $languageKey,
+                       'charset' => $charset
+               );
+
+               $fileWithoutExtension = t3lib_div::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
+
+               foreach ($this->supportedExtensions as $extension) {
+                       if (@is_file($fileWithoutExtension . '.' . $extension)) {
+                               $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
+                               $this->configuration[$fileReference]['fileExtension'] = $extension;
+                               break;
+                       }
+               }
+
+               if ($this->configuration[$fileReference]['fileExtension'] === FALSE) {
+                       throw new t3lib_l10n_exception_FileNotFound(
+                               sprintf('Source localization file (%s) not found', $fileReference),
+                               1306410755
+                       );
+               }
+
+               $extension = $this->configuration[$fileReference]['fileExtension'];
+
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
+                       $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
+               } else {
+                       throw new t3lib_l10n_exception_InvalidParser(
+                               'TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.',
+                               1301579637
+                       );
+               }
+
+               if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
+                       throw new t3lib_l10n_exception_InvalidParser(
+                               'TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!',
+                               1270853900
+                       );
+               }
+
+               return $this;
+       }
+
+       /**
+        * Get the filereference without the extension
+        *
+        * @param string $fileReference File reference
+        * @return string
+        */
+       public function getFileReferenceWithoutExtension($fileReference) {
+               if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
+                       $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\.[a-z0-9]+$/i' , '' , $fileReference);
+               }
+               return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
+       }
+
+       /**
+        * Returns the correct parser for a specific file reference.
+        *
+        * @throws t3lib_l10n_exception_InvalidParser
+        * @param string $fileReference File reference
+        * @return t3lib_l10n_parser
+        */
+       public function getParserInstance($fileReference) {
+               if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
+                       return t3lib_div::makeInstance((string) $this->configuration[$fileReference]['parserClass']);
+               } else {
+                       throw new t3lib_l10n_exception_InvalidParser(
+                               sprintf('Invalid parser configuration for the current file (%s)', $fileReference),
+                               1307293692
+                       );
+               }
+       }
+
+       /**
+        * Gets the absolute file path.
+        *
+        * @throws InvalidArgumentException
+        * @param string $fileReference
+        * @return string
+        */
+       public function getAbsoluteFileReference($fileReference) {
+               if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
+                       return (string) $this->configuration[$fileReference]['fileReference'];
+               } else {
+                       throw new InvalidArgumentException(
+                               sprintf('Invalid file reference configuration for the current file (%s)', $fileReference),
+                               1307293692
+                       );
+               }
+       }
+
+       /**
+        * Get supported extensions
+        *
+        * @return array
+        */
+       public function getSupportedExtensions() {
+               return $this->supportedExtensions;
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/exception/class.t3lib_l10n_exception_filenotfound.php b/t3lib/l10n/exception/class.t3lib_l10n_exception_filenotfound.php
new file mode 100644 (file)
index 0000000..94366cb
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * File not found exception
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_exception_FileNotFound extends RuntimeException {
+
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/exception/class.t3lib_l10n_exception_invalidparser.php b/t3lib/l10n/exception/class.t3lib_l10n_exception_invalidparser.php
new file mode 100644 (file)
index 0000000..be7c1bf
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Invalid Parser exception
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_exception_InvalidParser extends RuntimeException {
+
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/exception/class.t3lib_l10n_exception_invalidxmlfile.php b/t3lib/l10n/exception/class.t3lib_l10n_exception_invalidxmlfile.php
new file mode 100644 (file)
index 0000000..425d143
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Invalid XML file exception
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_exception_InvalidXmlFile extends RuntimeException {
+
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/interfaces/interface.t3lib_l10n_parser.php b/t3lib/l10n/interfaces/interface.t3lib_l10n_parser.php
new file mode 100644 (file)
index 0000000..830d446
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Parser interface.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+interface t3lib_l10n_parser {
+
+       /**
+        * Returns parsed representation of XML file.
+        *
+        * @param string $sourcePath Source file path
+        * @param string $languageKey Language key
+        * @param string $charset Charset
+        * @return array
+        */
+       public function getParsedData($sourcePath, $languageKey, $charset);
+
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/parser/class.t3lib_l10n_parser_abstractxml.php b/t3lib/l10n/parser/class.t3lib_l10n_parser_abstractxml.php
new file mode 100644 (file)
index 0000000..f2dd2f9
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Abstract class for XML based parser.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+abstract class t3lib_l10n_parser_AbstractXml implements t3lib_l10n_parser {
+
+       /**
+        * @var string
+        */
+       protected $sourcePath;
+
+       /**
+        * @var string
+        */
+       protected $languageKey;
+
+       /**
+        * @var string
+        */
+       protected $charset;
+
+       /**
+        * Returns parsed representation of XML file.
+        *
+        * @throws t3lib_l10n_exception_FileNotFound
+        * @param string $sourcePath Source file path
+        * @param string $languageKey Language key
+        * @param string $charset File charset
+        * @return array
+        */
+       public function getParsedData($sourcePath, $languageKey, $charset = '') {
+               $this->sourcePath = $sourcePath;
+               $this->languageKey = $languageKey;
+               $this->charset = $this->getCharset($languageKey, $charset);
+
+               if (($this->languageKey !== 'default' && $this->languageKey !== 'en')) {
+                       $this->sourcePath = t3lib_div::getFileAbsFileName(
+                               t3lib_div::llXmlAutoFileName($this->sourcePath, $this->languageKey)
+                       );
+
+                       if (!@is_file($this->sourcePath)) {
+                               throw new t3lib_l10n_exception_FileNotFound(
+                                       'Localization file does not exist',
+                                       1306332397
+                               );
+                       }
+               }
+
+               $LOCAL_LANG = array();
+               $LOCAL_LANG[$languageKey] = $this->parseXmlFile();
+
+               return $LOCAL_LANG;
+       }
+
+       /**
+        * Gets the character set to use.
+        *
+        * @param string $languageKey
+        * @param string $charset
+        * @return string
+        */
+       protected function getCharset($languageKey, $charset = '') {
+               /** @var $csConvObj t3lib_cs */
+               if (is_object($GLOBALS['LANG'])) {
+                       $csConvObj = $GLOBALS['LANG']->csConvObj;
+               } elseif (is_object($GLOBALS['TSFE'])) {
+                       $csConvObj = $GLOBALS['TSFE']->csConvObj;
+               } else {
+                       $csConvObj = t3lib_div::makeInstance('t3lib_cs');
+               }
+
+               if ($charset !== '') {
+                       $targetCharset = $csConvObj->parse_charset($charset);
+               } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
+                               // When forceCharset is set, we store ALL labels in this charset!!!
+                       $targetCharset = $csConvObj->parse_charset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
+               } else {
+                       $targetCharset = $csConvObj->parse_charset($csConvObj->charSetArray[$languageKey] ? $csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
+               }
+
+               return $targetCharset;
+       }
+
+       /**
+        * Loads the current XML file before processing.
+        *
+        * @throws t3lib_l10n_exception_InvalidXmlFile
+        * @return array An array representing parsed XML file (structure depends on concrete parser)
+        */
+       protected function parseXmlFile() {
+               $rootXmlNode = simplexml_load_file($this->sourcePath, 'SimpleXmlElement', \LIBXML_NOWARNING);
+
+               if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
+                       throw new t3lib_l10n_exception_InvalidXmlFile(
+                               'The path provided does not point to existing and accessible well-formed XML file.',
+                               1278155987
+                       );
+               }
+
+               return $this->doParsingFromRoot($rootXmlNode);
+       }
+
+       /**
+        * Returns array representation of XML data, starting from a root node.
+        *
+        * @abstract
+        * @param SimpleXMLElement $root A root node
+        * @return array An array representing the parsed XML file
+        */
+       abstract protected function doParsingFromRoot(SimpleXMLElement $root);
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/parser/class.t3lib_l10n_parser_llphp.php b/t3lib/l10n/parser/class.t3lib_l10n_parser_llphp.php
new file mode 100644 (file)
index 0000000..7b67541
--- /dev/null
@@ -0,0 +1,241 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Parser for PHP locallang array.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author Dominique Feyer <dfeyer@reelpeek.net>
+ * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
+ */
+class t3lib_l10n_parser_Llphp implements t3lib_l10n_parser {
+
+       /** @var string */
+       protected $cacheFileName;
+
+       /** @var t3lib_cs */
+       protected $csConvObj;
+
+       /** @var string */
+       protected $hashSource;
+
+       /** @var string */
+       protected $sourceCharset;
+
+       /** @var string */
+       protected $targetCharset;
+
+       /**
+        * Initializes the parser.
+        *
+        * @return void
+        */
+       public function __construct() {
+               $this->createCsConvObject();
+       }
+
+       /**
+        * Returns parsed representation of PHP locallang file.
+        *
+        * @throws RuntimeException
+        * @param string $sourcePath Source file path
+        * @param string $languageKey Language key
+        * @param string $charset Charset
+        * @return array
+        */
+       public function getParsedData($sourcePath, $languageKey, $charset = '') {
+               $this->validateParameters($sourcePath, $languageKey);
+               $this->setCharsets($languageKey, $charset);
+               $this->generateCacheFileName($sourcePath, $languageKey);
+
+               if (!file_exists($this->cacheFileName)) {
+                       $LOCAL_LANG = $this->generateCacheFile($sourcePath, $languageKey);
+               } else {
+                       $LOCAL_LANG = $this->getContentFromCacheFile();
+               }
+
+               $xliff = $this->convertToXLIFF($LOCAL_LANG);
+
+               return $xliff;
+       }
+
+       /**
+        * Converts the LOCAL_LANG array to XLIFF structure.
+        *
+        * @param array $LOCAL_LANG
+        * @return array
+        */
+       protected function convertToXLIFF(array $LOCAL_LANG) {
+               foreach ($LOCAL_LANG as &$keysLabels) {
+                       foreach ($keysLabels as &$label) {
+                               $label = array(0 => array(
+                                       'target' => $label,
+                               ));
+                       }
+                       unset($label);
+               }
+               return $LOCAL_LANG;
+       }
+
+       /**
+        * Creates a character conversion object.
+        *
+        * @return void
+        */
+       protected function createCsConvObject() {
+               if (is_object($GLOBALS['LANG'])) {
+                       $this->csConvObj = $GLOBALS['LANG']->csConvObj;
+               } elseif (is_object($GLOBALS['TSFE'])) {
+                       $this->csConvObj = $GLOBALS['TSFE']->csConvObj;
+               } else {
+                       $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
+               }
+       }
+
+       /**
+        * Generates the cache file.
+        *
+        * @throws RuntimeException
+        * @param string $sourcePath
+        * @param string $languageKey
+        * @return array
+        */
+       protected function generateCacheFile($sourcePath, $languageKey) {
+               $LOCAL_LANG = array();
+
+                       // Get PHP data
+               include($sourcePath);
+               if (!is_array($LOCAL_LANG)) {
+                       $fileName = substr($sourcePath, strlen(PATH_site));
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: "' . $fileName . '" is no TYPO3 language file!',
+                               1308898491
+                       );
+               }
+
+                       // Converting the default language (English)
+                       // This needs to be done for a few accented loan words and extension names
+               if (is_array($LOCAL_LANG['default']) && $this->targetCharset !== 'iso-8859-1') {
+                       foreach ($LOCAL_LANG['default'] as &$labelValue) {
+                               $labelValue = $this->csConvObj->conv($labelValue, 'iso-8859-1', $this->targetCharset);
+                       }
+                       unset($labelValue);
+               }
+
+               if ($languageKey !== 'default' && is_array($LOCAL_LANG[$languageKey]) && $this->sourceCharset != $this->targetCharset) {
+                       foreach ($LOCAL_LANG[$languageKey] as &$labelValue) {
+                               $labelValue = $this->csConvObj->conv($labelValue, $this->sourceCharset, $this->targetCharset);
+                       }
+                       unset($labelValue);
+               }
+
+               // Cache the content now:
+               $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default'], $languageKey => $LOCAL_LANG[$languageKey]));
+               $res = t3lib_div::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
+               if ($res) {
+                       throw new RuntimeException(
+                               'TYPO3 Fatal Error: "' . $res,
+                               1308898501
+                       );
+               }
+               return $LOCAL_LANG;
+       }
+
+       /**
+        * Generates the name of the cached file.
+        *
+        * @param string $sourcePath
+        * @param string $languageKey
+        * @return void
+        */
+       protected function generateCacheFileName($sourcePath, $languageKey) {
+               $this->hashSource = substr($sourcePath, strlen(PATH_site)) . '|' . date('d-m-Y H:i:s', filemtime($sourcePath)) . '|version=2.3';
+               $this->cacheFileName = PATH_site . 'typo3temp/llxml/' .
+                       substr(basename($sourcePath), 10, 15) .
+                       '_' . t3lib_div::shortMD5($this->hashSource) . '.' . $languageKey .
+                       '.' . $this->targetCharset . '.cache';
+       }
+
+       /**
+        * Obtains the content from the cache file.
+        *
+        * @return array
+        */
+       protected function getContentFromCacheFile() {
+               $serContent = (array)unserialize(file_get_contents($this->cacheFileName));
+               $LOCAL_LANG = $serContent['LOCAL_LANG'];
+               return (array)$LOCAL_LANG;
+       }
+
+       /**
+        * Checks if the file is within the web root.
+        *
+        * @param string $fileName
+        * @return bool
+        */
+       protected function isWithinWebRoot($fileName) {
+               return (bool)t3lib_div::getFileAbsFileName($fileName);
+       }
+
+       /**
+        * Sets character sets for the language key.
+        *
+        * @param string $languageKey
+        * @param string $charset
+        * @return void
+        */
+       protected function setCharsets($languageKey, $charset) {
+               $this->sourceCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$languageKey]
+                       ? $this->csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
+               if ($charset) {
+                       $this->targetCharset = $this->csConvObj->parse_charset($charset);
+               } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
+                               // When forceCharset is set, we store ALL labels in this charset!!!
+                       $this->targetCharset = $this->csConvObj->parse_charset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
+               } else {
+                       $this->targetCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$languageKey]
+                               ? $this->csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
+               }
+       }
+
+       /**
+        * Validates parameters for the function.
+        *
+        * @throws RuntimeException
+        * @param string $sourcePath
+        * @param string $languageKey
+        * @return void
+        */
+       protected function validateParameters($sourcePath, $languageKey) {
+               if (!$this->isWithinWebRoot($sourcePath) || !@is_file($sourcePath) || !$languageKey) {
+                       throw new RuntimeException(sprintf('Invalid source path (%s) or languageKey (%s)', $sourcePath, $languageKey), 1309245002);
+               }
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/parser/class.t3lib_l10n_parser_llxml.php b/t3lib/l10n/parser/class.t3lib_l10n_parser_llxml.php
new file mode 100644 (file)
index 0000000..7472280
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Parser for XML locallang file.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_parser_Llxml extends t3lib_l10n_parser_AbstractXml {
+
+       /**
+        * Associative array of "filename => parsed data" pairs.
+        *
+        * @var array
+        */
+       protected $parsedTargetFiles;
+
+       /**
+        * Returns parsed representation of XML file.
+        *
+        * @param string $sourcePath Source file path
+        * @param string $languageKey Language key
+        * @param string $charset Charset
+        * @return array
+        */
+       public function getParsedData($sourcePath, $languageKey, $charset = '') {
+               $this->sourcePath = $sourcePath;
+               $this->languageKey = $languageKey;
+               $this->charset = $this->getCharset($languageKey, $charset);
+
+                       // Parse source
+               $parsedSource = $this->parseXmlFile();
+
+                       // Parse target
+               $localizedTargetPath = t3lib_div::getFileAbsFileName(t3lib_div::llXmlAutoFileName($this->sourcePath, $this->languageKey));
+               $targetPath = ($this->languageKey !== 'default' && @is_file($localizedTargetPath)) ? $localizedTargetPath : $this->sourcePath;
+
+               try {
+                       $parsedTarget = $this->getParsedTargetData($targetPath);
+               } catch (t3lib_l10n_exception_InvalidXmlFile $e) {
+                       $parsedTarget = $this->getParsedTargetData($this->sourcePath);
+               }
+
+               $LOCAL_LANG = array();
+               $LOCAL_LANG[$languageKey] = t3lib_div::array_merge_recursive_overrule($parsedSource, $parsedTarget);
+
+               return $LOCAL_LANG;
+       }
+
+       /**
+        * Returns array representation of XLIFF data, starting from a root node.
+        *
+        * @param SimpleXMLElement $root XML root element
+        * @param string $element Target or Source
+        * @return array
+        */
+       protected function _doParsingFromRoot(SimpleXMLElement $root, $element) {
+               $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,
+                               );
+                       }
+               }
+
+               return $parsedData;
+       }
+
+       /**
+        * Returns array representation of XLIFF data, starting from a root node.
+        *
+        * @param \SimpleXMLElement $root A root node
+        * @return array An array representing parsed XLIFF
+        * @todo Support "approved" attribute
+        */
+       protected function doParsingFromRoot(SimpleXMLElement $root) {
+               return $this->_doParsingFromRoot($root, 'source');
+       }
+
+       /**
+        * Returns array representation of XLIFF data, starting from a root node.
+        *
+        * @param \SimpleXMLElement $root A root node
+        * @return array An array representing parsed XLIFF
+        * @todo Support "approved" attribute
+        */
+       protected function doParsingTargetFromRoot(SimpleXMLElement $root) {
+               return $this->_doParsingFromRoot($root, 'target');
+       }
+
+       /**
+        * Returns parsed representation of XML file.
+        *
+        * Parses XML if it wasn't done before. Caches parsed data.
+        *
+        * @param string $path An absolute path to XML file
+        * @return array Parsed XML file
+        */
+       public function getParsedTargetData($path) {
+               if (!isset($this->parsedTargetFiles[$path])) {
+                       $this->parsedTargetFiles[$path] = $this->parseXmlTargetFile($path);
+               }
+               return $this->parsedTargetFiles[$path];
+       }
+
+       /**
+        * Reads and parses XML file and returns internal representation of data.
+        *
+        * @throws t3lib_l10n_exception_InvalidXmlFile
+        * @param string $targetPath Path of the target file
+        * @return array
+        */
+       protected function parseXmlTargetFile($targetPath) {
+               $rootXmlNode = FALSE;
+
+               if (file_exists($targetPath)) {
+                       $rootXmlNode = simplexml_load_file($targetPath, 'SimpleXmlElement', \LIBXML_NOWARNING);
+               }
+
+               if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
+                       throw new t3lib_l10n_exception_InvalidXmlFile('The path provided does not point to existing and accessible well-formed XML file (' . $targetPath . ').', 1278155987);
+               }
+
+               return $this->doParsingTargetFromRoot($rootXmlNode);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php b/t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php
new file mode 100644 (file)
index 0000000..fff1155
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Parser for XLIFF file.
+ *
+ * @package    TYPO3
+ * @subpackage t3lib
+ * @author     Dominique Feyer <dfeyer@reelpeek.net>
+ */
+class t3lib_l10n_parser_Xliff extends t3lib_l10n_parser_AbstractXml {
+
+       /**
+        * Returns array representation of XML data, starting from a root node.
+        *
+        * @param SimpleXMLElement $root A root node
+        * @return array An array representing the parsed XML file
+        */
+       protected function doParsingFromRoot(SimpleXMLElement $root) {
+               $parsedData = array();
+               $bodyOfFileTag = $root->file->body;
+
+               foreach ($bodyOfFileTag->children() as $translationElement) {
+                       if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
+                                       // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
+
+                               $parsedData[(string)$translationElement['id']][0] = array(
+                                       'source' => (string)$translationElement->source,
+                                       'target' => (string)$translationElement->target,
+                               );
+                       } elseif ($translationElement->getName() === 'group' && isset($translationElement['restype']) && (string)$translationElement['restype'] === 'x-gettext-plurals') {
+                                       // This is a translation with plural forms
+                               $parsedTranslationElement = array();
+
+                               foreach ($translationElement->children() as $translationPluralForm) {
+                                       if ($translationPluralForm->getName() === 'trans-unit') {
+                                                       // When using plural forms, ID looks like this: 1[0], 1[1] etc
+                                               $formIndex = substr((string)$translationPluralForm['id'], strpos((string)$translationPluralForm['id'], '[') + 1, -1);
+
+                                               $parsedTranslationElement[(int)$formIndex] = array(
+                                                       'source' => (string)$translationPluralForm->source,
+                                                       'target' => (string)$translationPluralForm->target,
+                                               );
+                                       }
+                               }
+
+                               if (!empty($parsedTranslationElement)) {
+                                       if (isset($translationElement['id'])) {
+                                               $id = (string)$translationElement['id'];
+                                       } else {
+                                               $id = (string)($translationElement->{'trans-unit'}[0]['id']);
+                                               $id = substr($id, 0, strpos($id, '['));
+                                       }
+
+                                       $parsedData[$id] = $parsedTranslationElement;
+                               }
+                       }
+               }
+
+               return $parsedData;
+       }
+}
+
+?>
\ No newline at end of file
index 78b6aef..8ff5a93 100644 (file)
@@ -1740,12 +1740,12 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        // Set override file
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
 
-               /** @var $store tx_lang_Store */
-               $store = t3lib_div::makeInstance('tx_lang_Store');
+               /** @var $store t3lib_l10n_Store */
+               $store = t3lib_div::makeInstance('t3lib_l10n_Store');
                $store->flushData('EXT:lang/locallang_core.xml');
 
-                       // Manually flush cache (because lang_l10n cannot be recreated automatically at this point)
-               $cacheDirectory = PATH_site . 'typo3temp/Cache/Data/lang_l10n/';
+                       // Manually flush cache (because t3lib_l10n cannot be recreated automatically at this point)
+               $cacheDirectory = PATH_site . 'typo3temp/Cache/Data/t3lib_l10n/';
                $cacheFiles = t3lib_div::getFilesInDir($cacheDirectory);
                foreach ($cacheFiles as $cacheFile) {
                        @unlink($cacheDirectory . $cacheFile);
diff --git a/typo3/sysext/lang/classes/class.tx_lang_factory.php b/typo3/sysext/lang/classes/class.tx_lang_factory.php
deleted file mode 100644 (file)
index 7951ff2..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Provides a language parser factory.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_Factory implements t3lib_Singleton {
-
-       /**
-        * @var t3lib_cache_frontend_StringFrontend
-        */
-       protected $cacheInstance;
-
-       /**
-        * @var integer
-        */
-       protected $errorMode;
-
-       /**
-        * @var tx_lang_Store
-        */
-       public $store;
-
-       /**
-        * Class constructor
-        */
-       public function __construct() {
-               $this->initialize();
-       }
-
-       protected function initialize() {
-               $this->store = t3lib_div::makeInstance('tx_lang_Store');
-
-               $this->initializeCache();
-       }
-
-       /**
-        * Initialize cache instance to be ready to use
-        *
-        * @return void
-        */
-       protected function initializeCache() {
-               $this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('lang_l10n');
-       }
-
-       /**
-        * Returns parsed data from a given file and language key.
-        *
-        * @param string $fileReference Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a supported locallang file format
-        * @param string $languageKey Language key
-        * @param string $charset Character set (option); if not set, determined by the language key
-        * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
-        * @return array|bool
-        */
-       public function getParsedData($fileReference, $languageKey, $charset, $errorMode) {
-               try {
-                       $hash = md5($fileReference . $languageKey . $charset);
-                       $this->errorMode = $errorMode;
-
-                               // English is the default language
-                       $languageKey = ($languageKey === 'en') ? 'default' : $languageKey;
-
-                               // Check if the default language is processed before processing other language
-                       if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
-                               $this->getParsedData($fileReference, 'default', $charset, $this->errorMode);
-                       }
-
-                               // If the content is parsed (local cache), use it
-                       if ($this->store->hasData($fileReference, $languageKey)) {
-                               return $this->store->getData($fileReference);
-                       }
-
-                               // If the content is in cache (system cache), use it
-                       if ($this->cacheInstance->has($hash)) {
-                                       // Load data from the caching framework
-                               $this->store->setData($fileReference, $languageKey, $this->cacheInstance->get($hash));
-
-                               return $this->store->getData($fileReference, $languageKey);
-                       }
-
-                       $this->store->setConfiguration($fileReference, $languageKey, $charset);
-
-                       /** @var $parser tx_lang_parser */
-                       $parser = $this->store->getParserInstance($fileReference);
-
-                               // Get parsed data
-                       $LOCAL_LANG = $parser->getParsedData(
-                               $this->store->getAbsoluteFileReference($fileReference),
-                               $languageKey,
-                               $charset
-                       );
-
-                               // Override localization
-                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
-                               $this->localizationOverride($fileReference, $languageKey, $charset, $errorMode, $LOCAL_LANG);
-                       }
-
-                               // Save parsed data in cache
-                       $this->store->setData(
-                               $fileReference,
-                               $languageKey,
-                               $LOCAL_LANG[$languageKey]
-                       );
-
-                               // Cache processed data
-                       $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
-               } catch (tx_lang_exception_FileNotFound $exception) {
-                               // Source localization file not found
-                       $this->store->setData($fileReference, $languageKey, array());
-               }
-
-               return $this->store->getData($fileReference);
-       }
-
-       /**
-        * Override localization file
-        *
-        * This method merges the content of the override file with the default file
-        *
-        * @param string $fileReference
-        * @param string $languageKey
-        * @param string $charset
-        * @param integer $errorMode
-        * @param array $LOCAL_LANG
-        * @return void
-        */
-       protected function localizationOverride($fileReference, $languageKey, $charset, $errorMode, array &$LOCAL_LANG) {
-               $overrides = array();
-               $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
-
-               $locallangXMLOverride = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
-               foreach ($this->store->getSupportedExtensions() as $extension) {
-                       if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
-                               $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
-                       } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
-                               $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
-                       }
-               }
-
-               if (count($overrides) > 0) {
-                       foreach ($overrides as $overrideFile) {
-                               $languageOverrideFileName = t3lib_div::getFileAbsFileName($overrideFile);
-                               $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule(
-                                       $LOCAL_LANG,
-                                       $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode)
-                               );
-                       }
-               }
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/class.tx_lang_store.php b/typo3/sysext/lang/classes/class.tx_lang_store.php
deleted file mode 100644 (file)
index 5acb10b..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Language store.
- *
- * @package    Core
- * @subpackage tx_lang
- * @author     Dominique Feyer <dominique.feyer@reelpeek.net>
- */
-class tx_lang_Store implements t3lib_Singleton {
-
-       /**
-        * File extension supported by the localization parser
-        *
-        * @var array
-        */
-       protected $supportedExtensions;
-
-       /**
-        * Information about parsed file
-        *
-        * If data come from the cache, this array does not contain
-        * any information about this file
-        *
-        * @var array
-        */
-       protected $configuration;
-
-       /**
-        * Parsed localization file
-        *
-        * @var array
-        */
-       protected $data;
-
-       /**
-        * Constructor
-        */
-       public function __construct() {
-               $this->initialize();
-       }
-
-       /**
-        * Initializes the current class.
-        *
-        * @return void
-        */
-       public function initialize() {
-               if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
-                       $this->supportedExtensions = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
-               } else {
-                       $this->supportedExtensions = array('xlf', 'xml', 'php');
-               }
-       }
-
-       /**
-        * Checks if the store contains parsed data.
-        *
-        * @param string $fileReference File reference
-        * @param string $languageKey Valid language key
-        * @return bool
-        */
-       public function hasData($fileReference, $languageKey) {
-               if (isset($this->data[$fileReference][$languageKey]) && is_array($this->data[$fileReference][$languageKey])) {
-                       return TRUE;
-               }
-               return FALSE;
-       }
-
-       /**
-        * Retrieves data from the store.
-        *
-        * This method returns all parsed languages for the current file reference.
-        *
-        * @param string $fileReference File reference
-        * @return array
-        */
-       public function getData($fileReference) {
-               return $this->data[$fileReference];
-       }
-
-       /**
-        * Retrieves data from the store for a language.
-        *
-        * @param string $fileReference File reference
-        * @param string $languageKey Valid language key
-        * @return array
-        * @see self::getData()
-        */
-       public function getDataByLanguage($fileReference, $languageKey) {
-               return $this->data[$fileReference][$languageKey];
-       }
-
-       /**
-        * Sets data for a specific file reference and a language.
-        *
-        * @param string $fileReference File reference
-        * @param string $languageKey Valid language key
-        * @param $data
-        * @return tx_lang_Store This instance to allow method chaining
-        */
-       public function setData($fileReference, $languageKey, $data) {
-               $this->data[$fileReference][$languageKey] = $data;
-               return $this;
-       }
-
-       /**
-        * Flushes data.
-        *
-        * @param string $fileReference
-        * @return tx_lang_Store This instance to allow method chaining
-        */
-       public function flushData($fileReference) {
-               unset($this->data[$fileReference]);
-               return $this;
-       }
-
-       /**
-        * Checks file reference configuration (charset, extension, ...).
-        *
-        * @throws tx_lang_exception_InvalidParser|tx_lang_exception_FileNotFound
-        * @param string $fileReference File reference
-        * @param string $languageKey Valid language key
-        * @param string $charset Rendering charset
-        * @return tx_lang_Store This instance to allow method chaining
-        */
-       public function setConfiguration($fileReference, $languageKey, $charset) {
-               $this->configuration[$fileReference] = array(
-                       'fileReference' => $fileReference,
-                       'fileExtension' => FALSE,
-                       'parserClass' => NULL,
-                       'languageKey' => $languageKey,
-                       'charset' => $charset
-               );
-
-               $fileWithoutExtension = t3lib_div::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
-
-               foreach ($this->supportedExtensions as $extension) {
-                       if (@is_file($fileWithoutExtension . '.' . $extension)) {
-                               $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
-                               $this->configuration[$fileReference]['fileExtension'] = $extension;
-                               break;
-                       }
-               }
-
-               if ($this->configuration[$fileReference]['fileExtension'] === FALSE) {
-                       throw new tx_lang_exception_FileNotFound(
-                               sprintf('Source localization file (%s) not found', $fileReference),
-                               1306410755
-                       );
-               }
-
-               $extension = $this->configuration[$fileReference]['fileExtension'];
-
-               if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
-                       $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
-               } else {
-                       throw new tx_lang_exception_InvalidParser(
-                               'TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.',
-                               1301579637
-                       );
-               }
-
-               if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
-                       throw new tx_lang_exception_InvalidParser(
-                               'TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!',
-                               1270853900
-                       );
-               }
-
-               return $this;
-       }
-
-       /**
-        * Get the filereference without the extension
-        *
-        * @param string $fileReference File reference
-        * @return string
-        */
-       public function getFileReferenceWithoutExtension($fileReference) {
-               if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
-                       $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\.[a-z0-9]+$/i' , '' , $fileReference);
-               }
-               return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
-       }
-
-       /**
-        * Returns the correct parser for a specific file reference.
-        *
-        * @throws tx_lang_exception_InvalidParser
-        * @param string $fileReference File reference
-        * @return tx_lang_ParserInterface
-        */
-       public function getParserInstance($fileReference) {
-               if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
-                       return t3lib_div::makeInstance((string) $this->configuration[$fileReference]['parserClass']);
-               } else {
-                       throw new tx_lang_exception_InvalidParser(
-                               sprintf('Invalid parser configuration for the current file (%s)', $fileReference),
-                               1307293692
-                       );
-               }
-       }
-
-       /**
-        * Gets the absolute file path.
-        *
-        * @throws InvalidArgumentException
-        * @param string $fileReference
-        * @return string
-        */
-       public function getAbsoluteFileReference($fileReference) {
-               if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
-                       return (string) $this->configuration[$fileReference]['fileReference'];
-               } else {
-                       throw new InvalidArgumentException(
-                               sprintf('Invalid file reference configuration for the current file (%s)', $fileReference),
-                               1307293692
-                       );
-               }
-       }
-
-       /**
-        * Get supported extensions
-        *
-        * @return array
-        */
-       public function getSupportedExtensions() {
-               return $this->supportedExtensions;
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/exception/class.tx_lang_exception_filenotfound.php b/typo3/sysext/lang/classes/exception/class.tx_lang_exception_filenotfound.php
deleted file mode 100644 (file)
index 72dc516..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * File not found exception
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_exception_FileNotFound extends RuntimeException {
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidparser.php b/typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidparser.php
deleted file mode 100644 (file)
index 3ea9436..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Invalid Parser exception
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_exception_InvalidParser extends RuntimeException {
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidxmlfile.php b/typo3/sysext/lang/classes/exception/class.tx_lang_exception_invalidxmlfile.php
deleted file mode 100644 (file)
index a076b34..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Invalid XML file exception
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_exception_InvalidXmlFile extends RuntimeException {
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/interfaces/interface.tx_lang_parser.php b/typo3/sysext/lang/classes/interfaces/interface.tx_lang_parser.php
deleted file mode 100644 (file)
index 9afc3cc..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Parser interface.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-interface tx_lang_parser {
-
-       /**
-        * Returns parsed representation of XML file.
-        *
-        * @param string $sourcePath Source file path
-        * @param string $languageKey Language key
-        * @param string $charset Charset
-        * @return array
-        */
-       public function getParsedData($sourcePath, $languageKey, $charset);
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/parser/class.tx_lang_parser_abstractxml.php b/typo3/sysext/lang/classes/parser/class.tx_lang_parser_abstractxml.php
deleted file mode 100644 (file)
index 1cb5625..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Abstract class for XML based parser.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-abstract class tx_lang_parser_AbstractXml implements tx_lang_parser {
-
-       /**
-        * @var string
-        */
-       protected $sourcePath;
-
-       /**
-        * @var string
-        */
-       protected $languageKey;
-
-       /**
-        * @var string
-        */
-       protected $charset;
-
-       /**
-        * Returns parsed representation of XML file.
-        *
-        * @throws tx_lang_exception_FileNotFound
-        * @param string $sourcePath Source file path
-        * @param string $languageKey Language key
-        * @param string $charset File charset
-        * @return array
-        */
-       public function getParsedData($sourcePath, $languageKey, $charset = '') {
-               $this->sourcePath = $sourcePath;
-               $this->languageKey = $languageKey;
-               $this->charset = $this->getCharset($languageKey, $charset);
-
-               if (($this->languageKey !== 'default' && $this->languageKey !== 'en')) {
-                       $this->sourcePath = t3lib_div::getFileAbsFileName(
-                               t3lib_div::llXmlAutoFileName($this->sourcePath, $this->languageKey)
-                       );
-
-                       if (!@is_file($this->sourcePath)) {
-                               throw new tx_lang_exception_FileNotFound(
-                                       'Localization file does not exist',
-                                       1306332397
-                               );
-                       }
-               }
-
-               $LOCAL_LANG = array();
-               $LOCAL_LANG[$languageKey] = $this->parseXmlFile();
-
-               return $LOCAL_LANG;
-       }
-
-       /**
-        * Gets the character set to use.
-        *
-        * @param string $languageKey
-        * @param string $charset
-        * @return string
-        */
-       protected function getCharset($languageKey, $charset = '') {
-               /** @var $csConvObj t3lib_cs */
-               if (is_object($GLOBALS['LANG'])) {
-                       $csConvObj = $GLOBALS['LANG']->csConvObj;
-               } elseif (is_object($GLOBALS['TSFE'])) {
-                       $csConvObj = $GLOBALS['TSFE']->csConvObj;
-               } else {
-                       $csConvObj = t3lib_div::makeInstance('t3lib_cs');
-               }
-
-               if ($charset !== '') {
-                       $targetCharset = $csConvObj->parse_charset($charset);
-               } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
-                               // When forceCharset is set, we store ALL labels in this charset!!!
-                       $targetCharset = $csConvObj->parse_charset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
-               } else {
-                       $targetCharset = $csConvObj->parse_charset($csConvObj->charSetArray[$languageKey] ? $csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
-               }
-
-               return $targetCharset;
-       }
-
-       /**
-        * Loads the current XML file before processing.
-        *
-        * @throws tx_lang_exception_InvalidXmlFile
-        * @return array An array representing parsed XML file (structure depends on concrete parser)
-        */
-       protected function parseXmlFile() {
-               $rootXmlNode = simplexml_load_file($this->sourcePath, 'SimpleXmlElement', \LIBXML_NOWARNING);
-
-               if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
-                       throw new tx_lang_exception_InvalidXmlFile(
-                               'The path provided does not point to existing and accessible well-formed XML file.',
-                               1278155987
-                       );
-               }
-
-               return $this->doParsingFromRoot($rootXmlNode);
-       }
-
-       /**
-        * Returns array representation of XML data, starting from a root node.
-        *
-        * @abstract
-        * @param SimpleXMLElement $root A root node
-        * @return array An array representing the parsed XML file
-        */
-       abstract protected function doParsingFromRoot(SimpleXMLElement $root);
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/parser/class.tx_lang_parser_llphp.php b/typo3/sysext/lang/classes/parser/class.tx_lang_parser_llphp.php
deleted file mode 100644 (file)
index f2c1abf..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Parser for PHP locallang array.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author Dominique Feyer <dfeyer@reelpeek.net>
- * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
- */
-class tx_lang_parser_Llphp implements tx_lang_parser {
-
-       /** @var string */
-       protected $cacheFileName;
-
-       /** @var t3lib_cs */
-       protected $csConvObj;
-
-       /** @var string */
-       protected $hashSource;
-
-       /** @var string */
-       protected $sourceCharset;
-
-       /** @var string */
-       protected $targetCharset;
-
-       /**
-        * Initializes the parser.
-        *
-        * @return void
-        */
-       public function __construct() {
-               $this->createCsConvObject();
-       }
-
-       /**
-        * Returns parsed representation of PHP locallang file.
-        *
-        * @throws RuntimeException
-        * @param string $sourcePath Source file path
-        * @param string $languageKey Language key
-        * @param string $charset Charset
-        * @return array
-        */
-       public function getParsedData($sourcePath, $languageKey, $charset = '') {
-               $this->validateParameters($sourcePath, $languageKey);
-               $this->setCharsets($languageKey, $charset);
-               $this->generateCacheFileName($sourcePath, $languageKey);
-
-               if (!file_exists($this->cacheFileName)) {
-                       $LOCAL_LANG = $this->generateCacheFile($sourcePath, $languageKey);
-               } else {
-                       $LOCAL_LANG = $this->getContentFromCacheFile();
-               }
-
-               $xliff = $this->convertToXLIFF($LOCAL_LANG);
-
-               return $xliff;
-       }
-
-       /**
-        * Converts the LOCAL_LANG array to XLIFF structure.
-        *
-        * @param array $LOCAL_LANG
-        * @return array
-        */
-       protected function convertToXLIFF(array $LOCAL_LANG) {
-               foreach ($LOCAL_LANG as &$keysLabels) {
-                       foreach ($keysLabels as &$label) {
-                               $label = array(0 => array(
-                                       'target' => $label,
-                               ));
-                       }
-                       unset($label);
-               }
-               return $LOCAL_LANG;
-       }
-
-       /**
-        * Creates a character conversion object.
-        *
-        * @return void
-        */
-       protected function createCsConvObject() {
-               if (is_object($GLOBALS['LANG'])) {
-                       $this->csConvObj = $GLOBALS['LANG']->csConvObj;
-               } elseif (is_object($GLOBALS['TSFE'])) {
-                       $this->csConvObj = $GLOBALS['TSFE']->csConvObj;
-               } else {
-                       $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
-               }
-       }
-
-       /**
-        * Generates the cache file.
-        *
-        * @throws RuntimeException
-        * @param string $sourcePath
-        * @param string $languageKey
-        * @return array
-        */
-       protected function generateCacheFile($sourcePath, $languageKey) {
-               $LOCAL_LANG = array();
-
-                       // Get PHP data
-               include($sourcePath);
-               if (!is_array($LOCAL_LANG)) {
-                       $fileName = substr($sourcePath, strlen(PATH_site));
-                       throw new RuntimeException(
-                               'TYPO3 Fatal Error: "' . $fileName . '" is no TYPO3 language file!',
-                               1308898491
-                       );
-               }
-
-                       // Converting the default language (English)
-                       // This needs to be done for a few accented loan words and extension names
-               if (is_array($LOCAL_LANG['default']) && $this->targetCharset !== 'iso-8859-1') {
-                       foreach ($LOCAL_LANG['default'] as &$labelValue) {
-                               $labelValue = $this->csConvObj->conv($labelValue, 'iso-8859-1', $this->targetCharset);
-                       }
-                       unset($labelValue);
-               }
-
-               if ($languageKey !== 'default' && is_array($LOCAL_LANG[$languageKey]) && $this->sourceCharset != $this->targetCharset) {
-                       foreach ($LOCAL_LANG[$languageKey] as &$labelValue) {
-                               $labelValue = $this->csConvObj->conv($labelValue, $this->sourceCharset, $this->targetCharset);
-                       }
-                       unset($labelValue);
-               }
-
-               // Cache the content now:
-               $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default'], $languageKey => $LOCAL_LANG[$languageKey]));
-               $res = t3lib_div::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
-               if ($res) {
-                       throw new RuntimeException(
-                               'TYPO3 Fatal Error: "' . $res,
-                               1308898501
-                       );
-               }
-               return $LOCAL_LANG;
-       }
-
-       /**
-        * Generates the name of the cached file.
-        *
-        * @param string $sourcePath
-        * @param string $languageKey
-        * @return void
-        */
-       protected function generateCacheFileName($sourcePath, $languageKey) {
-               $this->hashSource = substr($sourcePath, strlen(PATH_site)) . '|' . date('d-m-Y H:i:s', filemtime($sourcePath)) . '|version=2.3';
-               $this->cacheFileName = PATH_site . 'typo3temp/llxml/' .
-                       substr(basename($sourcePath), 10, 15) .
-                       '_' . t3lib_div::shortMD5($this->hashSource) . '.' . $languageKey .
-                       '.' . $this->targetCharset . '.cache';
-       }
-
-       /**
-        * Obtains the content from the cache file.
-        *
-        * @return array
-        */
-       protected function getContentFromCacheFile() {
-               $serContent = (array)unserialize(file_get_contents($this->cacheFileName));
-               $LOCAL_LANG = $serContent['LOCAL_LANG'];
-               return (array)$LOCAL_LANG;
-       }
-
-       /**
-        * Checks if the file is within the web root.
-        *
-        * @param string $fileName
-        * @return bool
-        */
-       protected function isWithinWebRoot($fileName) {
-               return (bool)t3lib_div::getFileAbsFileName($fileName);
-       }
-
-       /**
-        * Sets character sets for the language key.
-        *
-        * @param string $languageKey
-        * @param string $charset
-        * @return void
-        */
-       protected function setCharsets($languageKey, $charset) {
-               $this->sourceCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$languageKey]
-                       ? $this->csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
-               if ($charset) {
-                       $this->targetCharset = $this->csConvObj->parse_charset($charset);
-               } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
-                               // When forceCharset is set, we store ALL labels in this charset!!!
-                       $this->targetCharset = $this->csConvObj->parse_charset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
-               } else {
-                       $this->targetCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$languageKey]
-                               ? $this->csConvObj->charSetArray[$languageKey] : 'iso-8859-1');
-               }
-       }
-
-       /**
-        * Validates parameters for the function.
-        *
-        * @throws RuntimeException
-        * @param string $sourcePath
-        * @param string $languageKey
-        * @return void
-        */
-       protected function validateParameters($sourcePath, $languageKey) {
-               if (!$this->isWithinWebRoot($sourcePath) || !@is_file($sourcePath) || !$languageKey) {
-                       throw new RuntimeException(sprintf('Invalid source path (%s) or languageKey (%s)', $sourcePath, $languageKey), 1309245002);
-               }
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/parser/class.tx_lang_parser_llxml.php b/typo3/sysext/lang/classes/parser/class.tx_lang_parser_llxml.php
deleted file mode 100644 (file)
index 699071f..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Parser for XML locallang file.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_parser_Llxml extends tx_lang_parser_AbstractXml {
-
-       /**
-        * Associative array of "filename => parsed data" pairs.
-        *
-        * @var array
-        */
-       protected $parsedTargetFiles;
-
-       /**
-        * Returns parsed representation of XML file.
-        *
-        * @param string $sourcePath Source file path
-        * @param string $languageKey Language key
-        * @param string $charset Charset
-        * @return array
-        */
-       public function getParsedData($sourcePath, $languageKey, $charset = '') {
-               $this->sourcePath = $sourcePath;
-               $this->languageKey = $languageKey;
-               $this->charset = $this->getCharset($languageKey, $charset);
-
-                       // Parse source
-               $parsedSource = $this->parseXmlFile();
-
-                       // Parse target
-               $localizedTargetPath = t3lib_div::getFileAbsFileName(t3lib_div::llXmlAutoFileName($this->sourcePath, $this->languageKey));
-               $targetPath = ($this->languageKey !== 'default' && @is_file($localizedTargetPath)) ? $localizedTargetPath : $this->sourcePath;
-
-               try {
-                       $parsedTarget = $this->getParsedTargetData($targetPath);
-               } catch (tx_lang_exception_InvalidXmlFile $e) {
-                       $parsedTarget = $this->getParsedTargetData($this->sourcePath);
-               }
-
-               $LOCAL_LANG = array();
-               $LOCAL_LANG[$languageKey] = t3lib_div::array_merge_recursive_overrule($parsedSource, $parsedTarget);
-
-               return $LOCAL_LANG;
-       }
-
-       /**
-        * Returns array representation of XLIFF data, starting from a root node.
-        *
-        * @param SimpleXMLElement $root XML root element
-        * @param string $element Target or Source
-        * @return array
-        */
-       protected function _doParsingFromRoot(SimpleXMLElement $root, $element) {
-               $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,
-                               );
-                       }
-               }
-
-               return $parsedData;
-       }
-
-       /**
-        * Returns array representation of XLIFF data, starting from a root node.
-        *
-        * @param \SimpleXMLElement $root A root node
-        * @return array An array representing parsed XLIFF
-        * @todo Support "approved" attribute
-        */
-       protected function doParsingFromRoot(SimpleXMLElement $root) {
-               return $this->_doParsingFromRoot($root, 'source');
-       }
-
-       /**
-        * Returns array representation of XLIFF data, starting from a root node.
-        *
-        * @param \SimpleXMLElement $root A root node
-        * @return array An array representing parsed XLIFF
-        * @todo Support "approved" attribute
-        */
-       protected function doParsingTargetFromRoot(SimpleXMLElement $root) {
-               return $this->_doParsingFromRoot($root, 'target');
-       }
-
-       /**
-        * Returns parsed representation of XML file.
-        *
-        * Parses XML if it wasn't done before. Caches parsed data.
-        *
-        * @param string $path An absolute path to XML file
-        * @return array Parsed XML file
-        */
-       public function getParsedTargetData($path) {
-               if (!isset($this->parsedTargetFiles[$path])) {
-                       $this->parsedTargetFiles[$path] = $this->parseXmlTargetFile($path);
-               }
-               return $this->parsedTargetFiles[$path];
-       }
-
-       /**
-        * Reads and parses XML file and returns internal representation of data.
-        *
-        * @throws tx_lang_exception_InvalidXmlFile
-        * @param string $targetPath Path of the target file
-        * @return array
-        */
-       protected function parseXmlTargetFile($targetPath) {
-               $rootXmlNode = FALSE;
-
-               if (file_exists($targetPath)) {
-                       $rootXmlNode = simplexml_load_file($targetPath, 'SimpleXmlElement', \LIBXML_NOWARNING);
-               }
-
-               if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
-                       throw new tx_lang_exception_InvalidXmlFile('The path provided does not point to existing and accessible well-formed XML file (' . $targetPath . ').', 1278155987);
-               }
-
-               return $this->doParsingTargetFromRoot($rootXmlNode);
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/classes/parser/class.tx_lang_parser_xliff.php b/typo3/sysext/lang/classes/parser/class.tx_lang_parser_xliff.php
deleted file mode 100644 (file)
index 14d6d85..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Parser for XLIFF file.
- *
- * @package    TYPO3
- * @subpackage tx_lang
- * @author     Dominique Feyer <dfeyer@reelpeek.net>
- */
-class tx_lang_parser_Xliff extends tx_lang_parser_AbstractXml {
-
-       /**
-        * Returns array representation of XML data, starting from a root node.
-        *
-        * @param SimpleXMLElement $root A root node
-        * @return array An array representing the parsed XML file
-        */
-       protected function doParsingFromRoot(SimpleXMLElement $root) {
-               $parsedData = array();
-               $bodyOfFileTag = $root->file->body;
-
-               foreach ($bodyOfFileTag->children() as $translationElement) {
-                       if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
-                                       // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
-
-                               $parsedData[(string)$translationElement['id']][0] = array(
-                                       'source' => (string)$translationElement->source,
-                                       'target' => (string)$translationElement->target,
-                               );
-                       } elseif ($translationElement->getName() === 'group' && isset($translationElement['restype']) && (string)$translationElement['restype'] === 'x-gettext-plurals') {
-                                       // This is a translation with plural forms
-                               $parsedTranslationElement = array();
-
-                               foreach ($translationElement->children() as $translationPluralForm) {
-                                       if ($translationPluralForm->getName() === 'trans-unit') {
-                                                       // When using plural forms, ID looks like this: 1[0], 1[1] etc
-                                               $formIndex = substr((string)$translationPluralForm['id'], strpos((string)$translationPluralForm['id'], '[') + 1, -1);
-
-                                               $parsedTranslationElement[(int)$formIndex] = array(
-                                                       'source' => (string)$translationPluralForm->source,
-                                                       'target' => (string)$translationPluralForm->target,
-                                               );
-                                       }
-                               }
-
-                               if (!empty($parsedTranslationElement)) {
-                                       if (isset($translationElement['id'])) {
-                                               $id = (string)$translationElement['id'];
-                                       } else {
-                                               $id = (string)($translationElement->{'trans-unit'}[0]['id']);
-                                               $id = substr($id, 0, strpos($id, '['));
-                                       }
-
-                                       $parsedData[$id] = $parsedTranslationElement;
-                               }
-                       }
-               }
-
-               return $parsedData;
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/lang/ext_autoload.php b/typo3/sysext/lang/ext_autoload.php
deleted file mode 100644 (file)
index 152c979..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-// DO NOT CHANGE THIS FILE! It is automatically generated by extdeveval::buildAutoloadRegistry.
-// This file was generated on 2011-06-14 11:34
-
-$extensionPath = t3lib_extMgm::extPath('lang');
-$extensionClassesPath = t3lib_extMgm::extPath('lang') . 'classes/';
-return array(
-       'tx_lang_factory' => $extensionClassesPath . 'class.tx_lang_factory.php',
-       'tx_lang_store' => $extensionClassesPath . 'class.tx_lang_store.php',
-       'tx_lang_exception_filenotfound' => $extensionClassesPath . 'exception/class.tx_lang_exception_filenotfound.php',
-       'tx_lang_exception_invalidparser' => $extensionClassesPath . 'exception/class.tx_lang_exception_invalidparser.php',
-       'tx_lang_exception_invalidxmlfile' => $extensionClassesPath . 'exception/class.tx_lang_exception_invalidxmlfile.php',
-       'tx_lang_parser' => $extensionClassesPath . 'interfaces/interface.tx_lang_parser.php',
-       'tx_lang_parser_abstractxml' => $extensionClassesPath . 'parser/class.tx_lang_parser_abstractxml.php',
-       'tx_lang_parser_llphp' => $extensionClassesPath . 'parser/class.tx_lang_parser_llphp.php',
-       'tx_lang_parser_llxml' => $extensionClassesPath . 'parser/class.tx_lang_parser_llxml.php',
-       'tx_lang_parser_xliff' => $extensionClassesPath . 'parser/class.tx_lang_parser_xliff.php',
-);
-?>
\ No newline at end of file
index 677de77..da8bd39 100644 (file)
@@ -3,19 +3,19 @@ if (!defined ('TYPO3_MODE')) {
        die ('Access denied.');
 }
 
-       // Register cache lang_l10n
-if (!is_array($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['lang_l10n'])) {
-    $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['lang_l10n'] = array();
+       // Register cache t3lib_l10n
+if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3lib_l10n'])) {
+    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3lib_l10n'] = array();
 }
 
-if (!isset($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['lang_l10n']['backend'])) {
-    $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['lang_l10n']['backend'] = 't3lib_cache_backend_FileBackend';
+if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3lib_l10n']['backend'])) {
+    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['t3lib_l10n']['backend'] = 't3lib_cache_backend_FileBackend';
 }
 
        // Register Clear Cache Menu hook
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']['clearLangCache'] = 'EXT:lang/hooks/clearcache/class.tx_lang_clearcachemenu.php:&tx_lang_clearcachemenu';
 
        // Register Ajax call
-$TYPO3_CONF_VARS['BE']['AJAX']['lang::clearCache'] = 'EXT:lang/hooks/clearcache/class.tx_lang_clearcache.php:tx_lang_clearcache->clearCache';
+$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['lang::clearCache'] = 'EXT:lang/hooks/clearcache/class.tx_lang_clearcache.php:tx_lang_clearcache->clearCache';
 
 ?>
\ No newline at end of file
index 3d12a7d..0d0138c 100644 (file)
@@ -51,7 +51,7 @@ class tx_lang_clearcache {
         * @return void
         */
        protected function initializeCache() {
-               $this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('lang_l10n');
+               $this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('t3lib_l10n');
        }
 
        /**
index 94b8491..6975e42 100755 (executable)
@@ -127,7 +127,7 @@ class language {
 
        /**
         * instance of the parser factory
-        * @var tx_lang_Factory
+        * @var t3lib_l10n_Factory
         */
        public $parserFactory;
 
@@ -150,7 +150,7 @@ class language {
                $this->charSetArray = $this->csConvObj->charSetArray;
 
                        // Initialize the parser factory object
-               $this->parserFactory = t3lib_div::makeInstance('tx_lang_Factory');
+               $this->parserFactory = t3lib_div::makeInstance('t3lib_l10n_Factory');
 
                        // Internally setting the list of TYPO3 backend languages.
                $this->langSplit = TYPO3_languages;
@@ -191,7 +191,7 @@ class language {
        /**
         * Gets the parser factory.
         *
-        * @return tx_lang_Factory
+        * @return t3lib_l10n_Factory
         */
        public function getParserFactory() {
                return $this->parserFactory;