Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Last active June 28, 2016 14:35
Show Gist options
  • Save pumatertion/4737302 to your computer and use it in GitHub Desktop.
Save pumatertion/4737302 to your computer and use it in GitHub Desktop.
TYPO3 Flow Setting Locale How to detect User Language from HTTP Accept Language for usage by translateViewHelper
<?php
abstract class AbstractMyController extends extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* @Flow\Inject
* @var \TYPO3\Flow\I18n\Service
*/
protected $i18nService;
/**
* Initialize Method
* Using http accept language header to set the current locale settings
*/
public function initializeAction() {
parent::initializeAction();
$detector = new \TYPO3\Flow\I18n\Detector();
$acceptLanguageHeader = $this->request->getHttpRequest()->getHeaders()->get('Accept-Language');
$language = $detector->detectLocaleFromHttpHeader($acceptLanguageHeader);
$this->i18nService->getConfiguration()->setCurrentLocale($language);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment