53 lines
1.5 KiB
PHP
Raw Normal View History

2013-04-23 09:07:06 +00:00
<?php
2013-05-13 13:58:18 +00:00
class Application_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract
2013-04-23 09:07:06 +00:00
{
2013-05-13 13:58:18 +00:00
public function preDispatch(Zend_Controller_Request_Abstract $request)
2013-04-23 09:07:06 +00:00
{
$registry = Zend_Registry::getInstance();
$session = new Zend_Session_Namespace('Zend_Auth');
2013-04-23 09:07:06 +00:00
$translate = $registry->get('Zend_Translate');
$currLocale = $translate->getLocale();
2013-05-13 13:58:18 +00:00
Zend_Registry::get('firebug')->info('Plugin Language');
2013-04-23 09:07:06 +00:00
$user = new Scores_Utilisateur();
2013-05-13 13:58:18 +00:00
if ( $user->isLog() ) {
$lang = $request->getParam('lang', '');
switch ($lang) {
case "fr":
$langLocale = 'fr';
break;
case "en":
$langLocale = 'en';
break;
default:
$langLocale = $session->lang !='' ? $session->lang : $user->getLang();
}
} else {
$langLocale = 'fr';
2013-04-23 09:07:06 +00:00
}
2013-05-13 13:58:18 +00:00
2013-04-23 09:07:06 +00:00
$newLocale = new Zend_Locale();
$newLocale->setLocale($langLocale);
$registry->set('Zend_Locale', $newLocale);
2013-04-23 09:07:06 +00:00
$translate->setLocale($langLocale);
2013-05-13 13:58:18 +00:00
$this->setSessionLang($langLocale);
2013-04-23 09:07:06 +00:00
$registry->set('Zend_Translate', $translate);
}
2013-05-13 13:58:18 +00:00
/**
* Save new lang value into session
* @param string $lang
*/
protected function setSessionLang($lang)
{
$authStorage = Zend_Auth::getInstance()->getStorage();
$authData = $authStorage->read();
if($authData)
{
$authData->lang = $lang;
$authStorage->write($authData);
}
}
2013-04-23 09:07:06 +00:00
}