‪TYPO3CMS  10.4
LocalizationFactory.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
28 {
32  protected ‪$cacheInstance;
33 
37  public ‪$store;
38 
39  public function ‪__construct(‪LanguageStore $languageStore, ‪CacheManager $cacheManager)
40  {
41  $this->store = $languageStore;
42  $this->cacheInstance = $cacheManager->‪getCache('l10n');
43  }
44 
56  public function ‪getParsedData($fileReference, $languageKey, $_ = null, $__ = null, $isLocalizationOverride = false)
57  {
58  $hash = md5($fileReference . $languageKey);
59 
60  // Check if the default language is processed before processing other language
61  if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
62  $this->‪getParsedData($fileReference, 'default');
63  }
64  // If the content is parsed (local cache), use it
65  if ($this->store->hasData($fileReference, $languageKey)) {
66  return $this->store->getData($fileReference);
67  }
68 
69  // If the content is in cache (system cache), use it
70  ‪$data = $this->cacheInstance->get($hash);
71  if (‪$data !== false) {
72  $this->store->setData($fileReference, $languageKey, ‪$data);
73  return $this->store->getData($fileReference);
74  }
75 
76  try {
77  $this->store->setConfiguration($fileReference, $languageKey);
79  ‪$parser = $this->store->getParserInstance($fileReference);
80  // Get parsed data
81  ‪$LOCAL_LANG = ‪$parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey);
82  } catch (‪FileNotFoundException $exception) {
83  // Source localization file not found, set empty data as there could be an override
84  $this->store->setData($fileReference, $languageKey, []);
85  ‪$LOCAL_LANG = $this->store->getData($fileReference);
86  }
87 
88  // Override localization
89  if (!$isLocalizationOverride && isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
90  $this->‪localizationOverride($fileReference, $languageKey, ‪$LOCAL_LANG);
91  }
92 
93  // Save parsed data in cache
94  $this->store->setData($fileReference, $languageKey, ‪$LOCAL_LANG[$languageKey]);
95 
96  // Cache processed data
97  $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
98 
99  return $this->store->getData($fileReference);
100  }
101 
111  protected function ‪localizationOverride($fileReference, $languageKey, array &‪$LOCAL_LANG)
112  {
113  $overrides = [];
114  $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
115  $locallangXMLOverride = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
116  foreach ($this->store->getSupportedExtensions() as $extension) {
117  if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
118  $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
119  } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
120  $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
121  }
122  }
123  if (!empty($overrides)) {
124  foreach ($overrides as $overrideFile) {
125  $languageOverrideFileName = GeneralUtility::getFileAbsFileName($overrideFile);
126  $parsedData = $this->‪getParsedData($languageOverrideFileName, $languageKey, null, null, true);
127  if (is_array($parsedData)) {
129  }
130  }
131  }
132  }
133 }
‪TYPO3\CMS\Core\Localization\LocalizationFactory\localizationOverride
‪localizationOverride($fileReference, $languageKey, array &$LOCAL_LANG)
Definition: LocalizationFactory.php:109
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$store
‪TYPO3 CMS Core Localization LanguageStore $store
Definition: LocalizationFactory.php:35
‪TYPO3\CMS\Core\Cache\CacheManager\getCache
‪FrontendInterface getCache($identifier)
Definition: CacheManager.php:141
‪TYPO3\CMS\Core\Localization\LocalizationFactory\getParsedData
‪array< string, getParsedData( $fileReference, $languageKey, $_=null, $__=null, $isLocalizationOverride=false) { $hash=md5( $fileReference . $languageKey);if(! $this->store->hasData( $fileReference, 'default') &&$languageKey !=='default') { $this-> getParsedData($fileReference, 'default')
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:28
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:22
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$cacheInstance
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cacheInstance
Definition: LocalizationFactory.php:31
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Core\Localization
‪TYPO3\CMS\Core\Localization\LocalizationFactory\__construct
‪__construct(LanguageStore $languageStore, CacheManager $cacheManager)
Definition: LocalizationFactory.php:37
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$data
‪if($this->store->hasData($fileReference, $languageKey)) $data
Definition: LocalizationFactory.php:68
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:27
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$LOCAL_LANG
‪$LOCAL_LANG
Definition: LocalizationFactory.php:79
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$parser
‪$parser
Definition: LocalizationFactory.php:77
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46