issue #0001781: add logic to change language, using zend_translate

This commit is contained in:
Michael RICOIS 2013-11-13 12:27:04 +00:00
parent 2eb5440573
commit 9e3545391f
17 changed files with 4212 additions and 2 deletions

View File

@ -67,6 +67,23 @@ class UserController extends Zend_Controller_Action
$this->view->headMeta()->appendHttpEquiv('refresh', $refresh.'; url='.$url);
}
}
/**
* Changer la langue de l'utilisateur
*/
public function langAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$lang = $this->getRequest()->getParam('lang', null);
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$identity->langtmp = $lang;
$auth->getStorage()->write($identity);
}
}

BIN
application/languages/en.mo Normal file

Binary file not shown.

1773
application/languages/en.po Normal file

File diff suppressed because it is too large Load Diff

2341
application/languages/fr.po Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
<?php
//General
$this->translate('Accueil');
$this->translate('Préambule');
?>

View File

@ -1,3 +1,5 @@
<p class="info">
<a href="http://www.scores-decisions.com/">Scores & Décisions SAS</a>
<img class='flag' id='fr' src="/themes/default/images/drapeaux/fr.png"/>
<img class='flag' id='en' src="/themes/default/images/drapeaux/en.png"/>
</p>

View File

@ -0,0 +1 @@
<div class="infoData"></div>

View File

@ -0,0 +1,56 @@
<?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);
}
}

View File

@ -46,7 +46,10 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
$identity->timeout = $timeout;
$identity->time = time() + $timeout;
$lang = in_array($InfosLogin->result->lang, array('fr','en')) ? $InfosLogin->result->lang : 'fr';
$identity->lang = $lang;
$identity->langtmp = $lang;
/*
* Adresse Ip interdites
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

View File

@ -5,6 +5,12 @@ $(document).ready(function(){
function(){ $('#control').css('display', 'none'); }
);*/
$('img.flag').on('click', function() {
var url = window.location.href;
$.post('/user/lang', {lang: $(this).attr('id')}, function(data){
window.location.href = url;
});
});
$(window).scroll(function() {
var offset = $(window).scrollTop();

View File

@ -473,4 +473,10 @@ ul#fieldsblock li div.fieldgrp div.field .interval input[type=text] {
text-decoration: underline;
}
.ui-autocomplete-loading { background: white url('/libs/ui/themes/smoothness/images/ui-anim_basic_16x16.gif') right center no-repeat; }
.ui-autocomplete-loading { background: white url('/libs/ui/themes/smoothness/images/ui-anim_basic_16x16.gif') right center no-repeat; }
.flag {
cursor:pointer;
}