Skip to content

Instantly share code, notes, and snippets.

@pankajlele
Created April 17, 2014 06:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pankajlele/825a630953db4ff8c206 to your computer and use it in GitHub Desktop.
Save pankajlele/825a630953db4ff8c206 to your computer and use it in GitHub Desktop.
Aspect to switch i18n locale in Frontend
<?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