TYPO3 CMS  TYPO3_6-2
LocalizationFactory.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
30  protected $cacheInstance;
31 
35  protected $errorMode;
36 
40  public $store;
41 
45  public function __construct() {
46  $this->initialize();
47  }
48 
54  protected function initialize() {
55  $this->store = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore');
56  $this->initializeCache();
57  }
58 
64  protected function initializeCache() {
65  $this->cacheInstance = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n');
66  }
67 
78  public function getParsedData($fileReference, $languageKey, $charset, $errorMode, $isLocalizationOverride = FALSE) {
79  $hash = md5($fileReference . $languageKey . $charset);
80  $this->errorMode = $errorMode;
81  // Check if the default language is processed before processing other language
82  if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
83  $this->getParsedData($fileReference, 'default', $charset, $this->errorMode);
84  }
85  // If the content is parsed (local cache), use it
86  if ($this->store->hasData($fileReference, $languageKey)) {
87  return $this->store->getData($fileReference);
88  }
89 
90  // If the content is in cache (system cache), use it
91  $data = $this->cacheInstance->get($hash);
92  if ($data !== FALSE) {
93  $this->store->setData($fileReference, $languageKey, $data);
94  return $this->store->getData($fileReference);
95  }
96 
97  try {
98  $this->store->setConfiguration($fileReference, $languageKey, $charset);
100  $parser = $this->store->getParserInstance($fileReference);
101  // Get parsed data
102  $LOCAL_LANG = $parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey, $charset);
103  } catch (Exception\FileNotFoundException $exception) {
104  // Source localization file not found, set empty data as there could be an override
105  $this->store->setData($fileReference, $languageKey, array());
106  $LOCAL_LANG = $this->store->getData($fileReference);
107  }
108 
109  // Override localization
110  if (!$isLocalizationOverride && isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
111  $this->localizationOverride($fileReference, $languageKey, $charset, $errorMode, $LOCAL_LANG);
112  }
113 
114  // Save parsed data in cache
115  $this->store->setData($fileReference, $languageKey, $LOCAL_LANG[$languageKey]);
116 
117  // Cache processed data
118  $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
119 
120  return $this->store->getData($fileReference);
121  }
122 
135  protected function localizationOverride($fileReference, $languageKey, $charset, $errorMode, array &$LOCAL_LANG) {
136  $overrides = array();
137  $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
138  $locallangXMLOverride = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
139  foreach ($this->store->getSupportedExtensions() as $extension) {
140  if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
141  $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
142  } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
143  $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
144  }
145  }
146  if (count($overrides) > 0) {
147  foreach ($overrides as $overrideFile) {
148  $languageOverrideFileName = GeneralUtility::getFileAbsFileName($overrideFile);
149  ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG, $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode, TRUE));
150  }
151  }
152  }
153 
154 }
localizationOverride($fileReference, $languageKey, $charset, $errorMode, array &$LOCAL_LANG)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)