[FLOW3-general] localization with FLOW

Federico Bernardin typo3list at bernardin.it
Fri Dec 14 16:52:37 CET 2012


Great Bastian!

It works, I have to change:

protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) {
	$view->assign('locale', $this->locale);
}

with:

protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) {
	$view->assign('locale', $this->locale->getLanguage());
}

wonderful, thank you very much

cheers
Federico
 

Il giorno 14/dic/2012, alle ore 16:27, Bastian Waidelich <bastian at typo3.org> ha scritto:

> Federico Bernardin wrote:
> 
> Hi Federico,
> 
>> -
>>   name: 'language'
>>   uriPattern: '{@locale}/{@package}/{@controller}(/{@action})'
>>   defaults:
>>     '@package':    'MyPackage'
>>     '@controller': 'Standard'
>>     '@action':     'index'
>>     '@format':     'html'
> 
> The @ prefix is reserved for framework arguments (@package, @subpackage, @controller, @action & @format – see [1])
> 
> Try:
> 
> -
>  name: 'language'
>  uriPattern: '{locale}/{@package}/{@controller}(/{@action})'
>  defaults:
>    '@package':    'MyPackage'
>    '@controller': 'Standard'
>    '@action':     'index'
>    '@format':     'html'
> 
>> 
>> Then I create the initialize action into controller:
>> 
>> public function initializeAction(){
>> 		$arguments = $this->request->getArguments();
>> 		if(isset($arguments['@locale'])){
>> 			$localeDetector= $this->objectManager->get('TYPO3\FLOW3\I18n\Detector');
>> 			$locale = $localeDetector->detectLocaleFromLocaleTag($arguments['@locale']);
>> 			$i18nService = $this->objectManager->get('TYPO3\FLOW3\I18n\Service');
>> 			if ($i18nService->getConfiguration()->getCurrentLocale() !== $locale) {
>> 				$i18nService->getConfiguration()->setCurrentLocale($locale);
>> 			}
>> 		}
>> 	}
> 
> You forgot to make the locale available to the view.
> This could be achieved like this:
> 
> /**
> * @var \TYPO3\FLOW3\I18n\Detector
> * @FLOW3\Inject
> */
> protected $localeDetector;
> 
> /**
> * @var \TYPO3\FLOW3\I18n\Service
> * @FLOW3\Inject
> */
> protected $l18nService;
> 
> /**
> * @var \TYPO3\Flow\I18n\Locale
> */
> protected $locale;
> 
> public function initializeAction(){
> 	if ($this->request->hasArgument('locale')) {
> 		$this->locale = $this->localeDetector->detectLocaleFromLocaleTag($this->request->getArgument('locale'));
> 		if ($this->l18nService->getConfiguration()->getCurrentLocale() !== $this->locale) {
> 			$this->l18nService->getConfiguration()->setCurrentLocale($this->locale);
> 		}
> 	}
> }
> 
> /**
> * @param \TYPO3\Flow\Mvc\View\ViewInterface $view
> * @return void
> */
> protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) {
> 	$view->assign('locale', $this->locale);
> }
> 
> 
> 
> In your templates you'll then have to specify the locale argument like this:
> 
> <f:link.action action="index" arguments="{locale: locale}">foo</f:link.action>
> 
> 
> Or:
> 
> <f:link.action action="index" arguments="{locale: 'it'}">foo</f:link.action>
> 
> to set a different locale explicitly (note the single quotes around "it", they were missing in your code).
> 
> HTH
> 
> [1] http://flow.typo3.org/documentation/guide/partiii/routing.html#dynamic-route-parts
> 
> -- 
> Bastian Waidelich
> --
> Core Developer Team
> 
> TYPO3 .... inspiring people to share!
> Get involved: typo3.org
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general



More information about the FLOW3-general mailing list