‪TYPO3CMS  ‪main
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 
26 
31 {
35  protected ‪$cacheInstance;
36 
40  public ‪$store;
41 
42  public function ‪__construct(‪LanguageStore $languageStore, ‪CacheManager $cacheManager)
43  {
44  $this->store = $languageStore;
45  $this->cacheInstance = $cacheManager->‪getCache('l10n');
46  }
47 
59  public function ‪getParsedData($fileReference, $languageKey, $_ = null, $__ = null, $isLocalizationOverride = false)
60  {
61  $hash = md5($fileReference . $languageKey);
62 
63  // Check if the default language is processed before processing other language
64  if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
65  $this->‪getParsedData($fileReference, 'default');
66  }
67  // If the content is parsed (local cache), use it
68  if ($this->store->hasData($fileReference, $languageKey)) {
69  return $this->store->getData($fileReference);
70  }
71 
72  // If the content is in cache (system cache), use it
73  ‪$data = $this->cacheInstance->get($hash);
74  if (‪$data !== false) {
75  $this->store->setData($fileReference, $languageKey, ‪$data);
76  return $this->store->getData($fileReference);
77  }
78 
79  try {
80  $this->store->setConfiguration($fileReference, $languageKey);
81  ‪$parser = $this->store->getParserInstance($fileReference);
82  if (is_callable([‪$parser, 'parseExtensionResource']) && ‪PathUtility::isExtensionPath($fileReference)) {
83  $LOCAL_LANG = ‪$parser->parseExtensionResource($this->store->getAbsoluteFileReference($fileReference), $languageKey, $this->store->getLocalizedLabelsPathPattern($fileReference));
84  } else {
85  // @todo: this (providing an absolute file system path) likely does not work properly anyway in all cases and should rather be deprecated
86  $LOCAL_LANG = ‪$parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey);
87  }
88  } catch (FileNotFoundException | UnknownPackagePathException $exception) {
89  // Source localization file not found, set empty data as there could be an override
90  $this->store->setData($fileReference, $languageKey, []);
91  $LOCAL_LANG = $this->store->getData($fileReference);
92  }
93 
94  // Override localization
95  if (!$isLocalizationOverride && isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
96  $this->‪localizationOverride($fileReference, $languageKey, $LOCAL_LANG);
97  }
98 
99  // Save parsed data in cache
100  $this->store->setData($fileReference, $languageKey, $LOCAL_LANG[$languageKey]);
101 
102  // Cache processed data
103  $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
104 
105  return $this->store->getData($fileReference);
106  }
107 
117  protected function ‪localizationOverride($fileReference, $languageKey, array &$LOCAL_LANG)
118  {
119  $overrides = [];
120  $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
121  $locallangXMLOverride = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
122  foreach ($this->store->getSupportedExtensions() as $extension) {
123  if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
124  $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
125  } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
126  $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
127  }
128  }
129  if (!empty($overrides)) {
130  foreach ($overrides as $overrideFile) {
131  $languageOverrideFileName = $overrideFile;
132  if (!‪PathUtility::isExtensionPath($overrideFile)) {
133  $languageOverrideFileName = GeneralUtility::getFileAbsFileName($overrideFile);
134  }
135  $parsedData = $this->‪getParsedData($languageOverrideFileName, $languageKey, null, null, true);
136  if (is_array($parsedData)) {
137  ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG, $parsedData);
138  }
139  }
140  }
141  }
142 }
‪TYPO3\CMS\Core\Localization\LocalizationFactory\localizationOverride
‪localizationOverride($fileReference, $languageKey, array &$LOCAL_LANG)
Definition: LocalizationFactory.php:115
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$store
‪TYPO3 CMS Core Localization LanguageStore $store
Definition: LocalizationFactory.php:38
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:117
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Cache\CacheManager\getCache
‪FrontendInterface getCache($identifier)
Definition: CacheManager.php:128
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$cacheInstance
‪FrontendInterface $cacheInstance
Definition: LocalizationFactory.php:34
‪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:31
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:21
‪TYPO3\CMS\Core\Localization
Definition: CacheWarmer.php:18
‪TYPO3\CMS\Core\Localization\LocalizationFactory\__construct
‪__construct(LanguageStore $languageStore, CacheManager $cacheManager)
Definition: LocalizationFactory.php:40
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$data
‪if($this->store->hasData($fileReference, $languageKey)) $data
Definition: LocalizationFactory.php:71
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:31
‪TYPO3\CMS\Core\Package\Exception\UnknownPackagePathException
Definition: UnknownPackagePathException.php:23
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$parser
‪$parser
Definition: LocalizationFactory.php:79
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52