-
-
Save pankajlele/825a630953db4ff8c206 to your computer and use it in GitHub Desktop.
Aspect to switch i18n locale in Frontend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyCopnay\MyPackage\Aop; | |
/* * | |
* This script belongs to the MyCopnay.MyPackage. | |
* */ | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\Flow\I18n\Locale; | |
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | |
/** | |
* The FrontendI18nLocaleSwitchingAspect | |
* | |
* @Flow\Aspect | |
*/ | |
class FrontendI18nLocaleSwitchingAspect { | |
/** | |
* @Flow\Inject | |
* @var \TYPO3\Flow\I18n\Service | |
*/ | |
protected $localizationService; | |
/** | |
* Switches locale of i18n service depending on the locale in the Neos content context | |
* | |
* @Flow\Before("method(TYPO3\Neos\Controller\Frontend\NodeController->showAction())") | |
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point | |
* @return NodeInterface | |
*/ | |
public function switchLocale(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { | |
/** @var NodeInterface $node */ | |
$node = $joinPoint->getMethodArgument('node'); | |
$contextProperties = $node->getContext()->getProperties(); | |
if (isset($contextProperties['dimensions']['locales']) && is_array($contextProperties['dimensions']['locales'])) { | |
$locales = $contextProperties['dimensions']['locales']; | |
if ((!empty($locales))) { | |
$this->localizationService->getConfiguration()->setFallbackRule(array('strict' => FALSE, 'order' => $locales)); | |
$this->localizationService->getConfiguration()->setCurrentLocale(new Locale($locales[0])); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment