56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
class Application_Controller_Plugin_Lang extends Zend_Controller_Plugin_Abstract
|
|
{
|
|
/**
|
|
* Vérifie les autorisations
|
|
* Utilise _request et _response hérités et injectés par le FC
|
|
*
|
|
* @param Zend_Controller_Request_Abstract $request : non utilisé, mais demandé par l'héritage
|
|
*/
|
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if ( $auth->hasIdentity() ) {
|
|
$identity = $auth->getIdentity();
|
|
$lang = $identity->langtmp;
|
|
switch($lang) {
|
|
case 'en':
|
|
$locale = new Zend_Locale('en');
|
|
break;
|
|
case 'fr':
|
|
default:
|
|
$locale = new Zend_Locale('fr');
|
|
break;
|
|
}
|
|
} else {
|
|
$locale = new Zend_Locale('fr');
|
|
}
|
|
|
|
$cache = Zend_Cache::factory(
|
|
'Core',
|
|
'Apc',
|
|
array('lifetime' => 28800, 'automatic_serialization' => true),
|
|
array()
|
|
);
|
|
Zend_Translate::setCache($cache);
|
|
|
|
$translate = new Zend_Translate(
|
|
array(
|
|
'adapter' => 'gettext',
|
|
'content' => APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'fr.mo',
|
|
'locale' => 'fr',
|
|
)
|
|
);
|
|
$translate->addTranslation(
|
|
array(
|
|
'content' => APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'en.mo',
|
|
'locale' => 'en',
|
|
)
|
|
);
|
|
$translate->setLocale($locale);
|
|
|
|
$registry = Zend_Registry::getInstance();
|
|
$registry->set('Zend_Locale', $locale);
|
|
$registry->set('Zend_Translate', $translate);
|
|
}
|
|
} |