‪TYPO3CMS  9.5
LocalizationFactory.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
29  protected ‪$cacheInstance;
30 
34  public ‪$store;
35 
39  public function ‪__construct()
40  {
41  $this->store = GeneralUtility::makeInstance(LanguageStore::class);
42  $this->‪initializeCache();
43  }
44 
48  protected function ‪initializeCache()
49  {
50  $this->cacheInstance = GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n');
51  }
52 
63  public function ‪getParsedData($fileReference, $languageKey, $charset = '', $errorMode = null, $isLocalizationOverride = false)
64  {
65  // @deprecated since TYPO3 v9, will be removed with TYPO3 v10.0
66  // this is a fallback to convert references to old 'lang' locallang files to the new location
67  if (strpos($fileReference, 'EXT:lang/Resources/Private/Language/') === 0) {
68  $mapping = [
69  'lang/Resources/Private/Language/locallang_alt_intro.xlf' => 'about/Resources/Private/Language/Modules/locallang_alt_intro.xlf',
70  'lang/Resources/Private/Language/locallang_alt_doc.xlf' => 'backend/Resources/Private/Language/locallang_alt_doc.xlf',
71  'lang/Resources/Private/Language/locallang_login.xlf' => 'backend/Resources/Private/Language/locallang_login.xlf',
72  'lang/Resources/Private/Language/locallang_common.xlf' => 'core/Resources/Private/Language/locallang_common.xlf',
73  'lang/Resources/Private/Language/locallang_core.xlf' => 'core/Resources/Private/Language/locallang_core.xlf',
74  'lang/Resources/Private/Language/locallang_general.xlf' => 'core/Resources/Private/Language/locallang_general.xlf',
75  'lang/Resources/Private/Language/locallang_misc.xlf' => 'core/Resources/Private/Language/locallang_misc.xlf',
76  'lang/Resources/Private/Language/locallang_mod_web_list.xlf' => 'core/Resources/Private/Language/locallang_mod_web_list.xlf',
77  'lang/Resources/Private/Language/locallang_tca.xlf' => 'core/Resources/Private/Language/locallang_tca.xlf',
78  'lang/Resources/Private/Language/locallang_tsfe.xlf' => 'core/Resources/Private/Language/locallang_tsfe.xlf',
79  'lang/Resources/Private/Language/locallang_wizards.xlf' => 'core/Resources/Private/Language/locallang_wizards.xlf',
80  'lang/Resources/Private/Language/locallang_browse_links.xlf' => 'recordlist/Resources/Private/Language/locallang_browse_links.xlf',
81  'lang/Resources/Private/Language/locallang_tcemain.xlf' => 'workspaces/Resources/Private/Language/locallang_tcemain.xlf',
82  ];
83  $filePath = substr($fileReference, 4);
84  trigger_error('There is a reference to "' . $fileReference . '", which has been moved to "EXT:' . $mapping[$filePath] . '". This fallback will be removed with TYPO3 v10.0.', E_USER_DEPRECATED);
85  $fileReference = 'EXT:' . $mapping[$filePath];
86  }
87  // @deprecated since TYPO3 v9, will be removed with TYPO3 v10.0
88  // this is a fallback to convert references to old 'saltedpasswords' locallang files to the new location
89  if (strpos($fileReference, 'EXT:saltedpasswords/Resources/Private/Language/') === 0) {
90  $mapping = [
91  'saltedpasswords/Resources/Private/Language/locallang.xlf' => 'core/Resources/Private/Language/locallang_deprecated_saltedpasswords.xlf',
92  'saltedpasswords/Resources/Private/Language/locallang_em.xlf' => 'core/Resources/Private/Language/locallang_deprecated_saltedpasswords_em.xlf',
93  ];
94  $filePath = substr($fileReference, 4);
95  trigger_error('There is a reference to "' . $fileReference . '", which has been moved to "EXT:' . $mapping[$filePath] . '". This fallback will be removed with TYPO3 v10.0.', E_USER_DEPRECATED);
96  $fileReference = 'EXT:' . $mapping[$filePath];
97  }
98 
99  $hash = md5($fileReference . $languageKey);
100 
101  // Check if the default language is processed before processing other language
102  if (!$this->store->hasData($fileReference, 'default') && $languageKey !== 'default') {
103  $this->‪getParsedData($fileReference, 'default');
104  }
105  // If the content is parsed (local cache), use it
106  if ($this->store->hasData($fileReference, $languageKey)) {
107  return $this->store->getData($fileReference);
108  }
109 
110  // If the content is in cache (system cache), use it
111  $data = $this->cacheInstance->get($hash);
112  if ($data !== false) {
113  $this->store->setData($fileReference, $languageKey, $data);
114  return $this->store->getData($fileReference);
115  }
116 
117  try {
118  $this->store->setConfiguration($fileReference, $languageKey);
120  ‪$parser = $this->store->getParserInstance($fileReference);
121  // Get parsed data
122  $LOCAL_LANG = ‪$parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey);
123  } catch (‪Exception\‪FileNotFoundException $exception) {
124  // Source localization file not found, set empty data as there could be an override
125  $this->store->setData($fileReference, $languageKey, []);
126  $LOCAL_LANG = $this->store->getData($fileReference);
127  }
128 
129  // Override localization
130  if (!$isLocalizationOverride && isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
131  $this->‪localizationOverride($fileReference, $languageKey, $LOCAL_LANG);
132  }
133 
134  // Save parsed data in cache
135  $this->store->setData($fileReference, $languageKey, $LOCAL_LANG[$languageKey]);
136 
137  // Cache processed data
138  $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
139 
140  return $this->store->getData($fileReference);
141  }
142 
152  protected function ‪localizationOverride($fileReference, $languageKey, array &$LOCAL_LANG)
153  {
154  $overrides = [];
155  $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
156  $locallangXMLOverride = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
157  foreach ($this->store->getSupportedExtensions() as $extension) {
158  if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
159  $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
160  } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
161  $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
162  }
163  }
164  if (!empty($overrides)) {
165  foreach ($overrides as $overrideFile) {
166  $languageOverrideFileName = GeneralUtility::getFileAbsFileName($overrideFile);
167  ‪ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG, $this->‪getParsedData($languageOverrideFileName, $languageKey, null, null, true));
168  }
169  }
170  }
171 }
‪TYPO3\CMS\Core\Localization\LocalizationFactory\localizationOverride
‪localizationOverride($fileReference, $languageKey, array &$LOCAL_LANG)
Definition: LocalizationFactory.php:150
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$store
‪TYPO3 CMS Core Localization LanguageStore $store
Definition: LocalizationFactory.php:32
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:25
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:21
‪TYPO3\CMS\Core\Localization\LocalizationFactory\$cacheInstance
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cacheInstance
Definition: LocalizationFactory.php:28
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Localization
‪TYPO3\CMS\Core\Localization\LocalizationFactory\getParsedData
‪array bool getParsedData($fileReference, $languageKey, $charset='', $errorMode=null, $isLocalizationOverride=false)
Definition: LocalizationFactory.php:61
‪TYPO3\CMS\Core\Localization\LocalizationFactory\initializeCache
‪initializeCache()
Definition: LocalizationFactory.php:46
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Localization\LocalizationFactory\__construct
‪__construct()
Definition: LocalizationFactory.php:37