issue #0001781: add logic to change language, using zend_translate
This commit is contained in:
parent
2eb5440573
commit
9e3545391f
@ -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
BIN
application/languages/en.mo
Normal file
Binary file not shown.
1773
application/languages/en.po
Normal file
1773
application/languages/en.po
Normal file
File diff suppressed because it is too large
Load Diff
2341
application/languages/fr.po
Normal file
2341
application/languages/fr.po
Normal file
File diff suppressed because it is too large
Load Diff
5
application/languages/totranslate.php
Normal file
5
application/languages/totranslate.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
//General
|
||||
$this->translate('Accueil');
|
||||
$this->translate('Préambule');
|
||||
?>
|
@ -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>
|
1
application/views/default/scripts/user/lang.phtml
Normal file
1
application/views/default/scripts/user/lang.phtml
Normal file
@ -0,0 +1 @@
|
||||
<div class="infoData"></div>
|
56
library/Application/Controller/Plugin/Lang.php
Normal file
56
library/Application/Controller/Plugin/Lang.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
BIN
public/themes/default/images/drapeaux/be.png
Normal file
BIN
public/themes/default/images/drapeaux/be.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 545 B |
BIN
public/themes/default/images/drapeaux/de.png
Normal file
BIN
public/themes/default/images/drapeaux/de.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 545 B |
BIN
public/themes/default/images/drapeaux/en.png
Normal file
BIN
public/themes/default/images/drapeaux/en.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 599 B |
BIN
public/themes/default/images/drapeaux/fr.png
Normal file
BIN
public/themes/default/images/drapeaux/fr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 545 B |
BIN
public/themes/default/images/drapeaux/it.png
Normal file
BIN
public/themes/default/images/drapeaux/it.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 420 B |
BIN
public/themes/default/images/drapeaux/nl.png
Normal file
BIN
public/themes/default/images/drapeaux/nl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user