Skip to content

Commit

Permalink
compatibility TYPO3 11
Browse files Browse the repository at this point in the history
  • Loading branch information
franzholz committed Sep 4, 2024
1 parent ca4ea02 commit 74c0cc9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
21 changes: 16 additions & 5 deletions Classes/Base/TranslationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,28 @@ public function needsInit()

public function getLanguage()
{
$typo3VersionArray = VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version());
$typo3VersionMain = $typo3VersionArray['version_main'];
$typo3Language = 'en';
$request = $GLOBALS['TYPO3_REQUEST'];
$isFrontend = (ApplicationType::fromRequest($request)->isFrontend());
if ($isFrontend) {
$language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage();
if ($language->hasCustomTypo3Language()) {
$locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language());
if ($typo3VersionMain >= 12) {
$language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage();
if ($language->getTypo3Language() !== '') {
$locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language());
} else {
$locale = $language->getLocale();
}
$typo3Language = $locale->getLanguageCode();
} else {
$locale = $language->getLocale();
$tsfe = $this->getTypoScriptFrontendController();
if (
$tsfe instanceof TypoScriptFrontendController
) {
$typo3Language = $tsfe->getLanguage()->getTwoLetterIsoCode();
}
}
$typo3Language = $locale->getLanguageCode();
} else {
$currentSite = $this->getCurrentSite();
$currentSiteLanguage = $this->getCurrentSiteLanguage() ?? $currentSite?->getDefaultLanguage();
Expand Down
38 changes: 26 additions & 12 deletions Classes/Compatibility/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -226,27 +227,40 @@ class AbstractPlugin
*/
public function __construct($_ = null, TypoScriptFrontendController $frontendController = null)
{
$typo3VersionArray = VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version());
$typo3VersionMain = $typo3VersionArray['version_main'];
$request = $GLOBALS['TYPO3_REQUEST'];
$this->frontendController = $frontendController ?: $GLOBALS['TSFE'];
$this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
// Setting piVars:
if ($this->prefixId) {
$this->piVars = self::getRequestPostOverGetParameterWithPrefix($this->prefixId);
}
$language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage();
if ($language->hasCustomTypo3Language()) {
$locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language());
} else {
$locale = $language->getLocale();
}
if ($typo3VersionMain >= 12) {
$language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage();

$this->LLkey = $locale->getLanguageCode();
if ($language->getTypo3Language() !== '') {
$locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language());
} else {
$locale = $language->getLocale();
}

$locales = GeneralUtility::makeInstance(Locales::class);
if ($locales->isValidLanguageKey($this->LLkey)) {
$alternativeLanguageKeys = $locales->getLocaleDependencies($this->LLkey);
$alternativeLanguageKeys = array_reverse($alternativeLanguageKeys);
$this->altLLkey = implode(',', $alternativeLanguageKeys);
$this->LLkey = $locale->getLanguageCode();
$locales = GeneralUtility::makeInstance(Locales::class);
if ($locales->isValidLanguageKey($this->LLkey)) {
$alternativeLanguageKeys = $locales->getLocaleDependencies($this->LLkey);
$alternativeLanguageKeys = array_reverse($alternativeLanguageKeys);
$this->altLLkey = implode(',', $alternativeLanguageKeys);
}
} else {
$this->LLkey = $this->frontendController->getLanguage()->getTypo3Language();
$locales = GeneralUtility::makeInstance(Locales::class);
if (in_array($this->LLkey, $locales->getLocales())) {
foreach ($locales->getLocaleDependencies($this->LLkey) as $language) {
$this->altLLkey .= $language . ',';
}
$this->altLLkey = rtrim($this->altLLkey, ',');
}
}
}

Expand Down

0 comments on commit 74c0cc9

Please sign in to comment.