51 lines
1.6 KiB
PHP
51 lines
1.6 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');
|
||
|
}
|
||
|
|
||
|
$translate = new Zend_Translate(
|
||
|
array(
|
||
|
'adapter' => 'gettext',
|
||
|
'content' => APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'fr.mo',
|
||
|
'locale' => 'fr',
|
||
|
'scan' => Zend_Translate::LOCALE_DIRECTORY
|
||
|
)
|
||
|
);
|
||
|
|
||
|
$translate->addTranslation(
|
||
|
array(
|
||
|
'content' => APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'en.mo',
|
||
|
'locale' => 'en',
|
||
|
'scan' => Zend_Translate::LOCALE_DIRECTORY
|
||
|
)
|
||
|
);
|
||
|
$translate->setLocale($locale);
|
||
|
|
||
|
$registry = Zend_Registry::getInstance();
|
||
|
$registry->set('Zend_Locale', $locale);
|
||
|
$registry->set('Zend_Translate', $translate);
|
||
|
}
|
||
|
}
|