Skip to content

Commit

Permalink
Dev Translation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jul 22, 2014
1 parent 201914b commit c772cd1
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/nbproject
/tmp/assets/*
/tmp/runtime/cache/*
/framework
.svn
/third_party/jqgrid/src
.settings/org.eclipse.php.core.prefs
Expand Down
5 changes: 4 additions & 1 deletion application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
'class' => 'LSWebUser',
),
'log' => array(
'class' => 'CLogRouter'
'class' => 'CLogRouter',
'routes' => array(
'class' => 'CWebLogRoute'
)
),
'cache'=>array(
'class'=>'system.caching.CFileCache',
Expand Down
19 changes: 9 additions & 10 deletions application/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ public function getRegisterErrors($iSurveyId){
}

public function getRegisterForm($iSurveyId){
$clang = Yii::app()->lang;
$aSurveyInfo=getSurveyInfo($iSurveyId,$clang->langcode);

$aSurveyInfo=getSurveyInfo($iSurveyId,App()->language);
$sTemplate=getTemplatePath(validateTemplateDir($aSurveyInfo['template']));

// Event to replace register form
$event = new PluginEvent('beforeRegisterForm');
$event->set('surveyid', $iSurveyId);
$event->set('lang', $clang->langcode);
$event->set('lang', App()->language);
$event->set('aRegistersErrors', $this->aRegisterErrors);
App()->getPluginManager()->dispatchEvent($event);
// Allow adding error or replace error with plugin ?
Expand All @@ -176,8 +176,7 @@ public function getRegisterForm($iSurveyId){
$aFieldValue=$this->getFieldValue($iSurveyId);
$aRegisterAttributes=$this->getExtraAttributeInfo($iSurveyId);
$aData['iSurveyId'] = $iSurveyId;
$aData['sLanguage'] = $clang->langcode;
$aData['clang'] = $clang;
$aData['sLanguage'] = App()->language;
$aData['sFirstName'] = $aFieldValue['sFirstName'];
$aData['sLastName'] = $aFieldValue['sLastName'];
$aData['sEmail'] = $aFieldValue['sEmail'];
Expand All @@ -200,7 +199,7 @@ public function getRegisterForm($iSurveyId){

$aData['thissurvey'] = $aSurveyInfo;
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
$aData['languagechanger'] = makeLanguageChangerSurvey($clang->langcode);
$aData['languagechanger'] = makeLanguageChangerSurvey(App()->language);
return templatereplace(file_get_contents("$sTemplate/register.pstpl"),$aReplacement,$aData);
}

Expand All @@ -210,8 +209,8 @@ public function getRegisterForm($iSurveyId){
* @return boolean : if email is set to sent (before SMTP problem)
*/
public function sendRegistrationEmail($iSurveyId,$iTokenId){
$clang = Yii::app()->lang;
$sLanguage=$clang->langcode;

$sLanguage=App()->language;
$aSurveyInfo=getSurveyInfo($iSurveyId,$sLanguage);

$aMail['subject']=$aSurveyInfo['email_register_subj'];
Expand Down Expand Up @@ -301,8 +300,8 @@ public function sendRegistrationEmail($iSurveyId,$iTokenId){
*/
public function getTokenId($iSurveyId)
{
$clang = Yii::app()->lang;
$sLanguage=$clang->langcode;

$sLanguage=App()->language;
$aSurveyInfo=getSurveyInfo($iSurveyId,$sLanguage);

$aFieldValue=$this->getFieldValue($iSurveyId);
Expand Down
5 changes: 0 additions & 5 deletions application/controllers/Statistics_userController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ function actionAction($surveyid,$language)
$language = Survey::model()->findByPk($iSurveyID)->language;


//set survey language for translations
$clang = SetSurveyLanguage($iSurveyID, $language);


//Create header (fixes bug #3097)
$surveylanguage= $language;
sendCacheHeaders();
Expand Down Expand Up @@ -410,7 +406,6 @@ function actionAction($surveyid,$language)
}
$data['thisSurveyTitle'] = $thisSurveyTitle;
$data['totalrecords'] = $totalrecords;
$data['clang'] = $clang;
$data['summary'] = $summary;
//show some main data at the beginnung
// CHANGE JSW_NZ - let's allow html formatted questions to show
Expand Down
2 changes: 0 additions & 2 deletions application/controllers/SurveyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ protected function _init()
{
parent::_init();

$this->_sessioncontrol();

unset(Yii::app()->session['FileManagerContext']);

if (!Yii::app()->getConfig("surveyid")) {Yii::app()->setConfig("surveyid", returnGlobal('sid'));} //SurveyID
Expand Down
1 change: 0 additions & 1 deletion application/controllers/UploaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function run($actionID)
$sLanguage='';
}

$clang = SetSurveyLanguage( $surveyid, $sLanguage);
$uploaddir = Yii::app()->getConfig("uploaddir");
$tempdir = Yii::app()->getConfig("tempdir");

Expand Down
15 changes: 8 additions & 7 deletions application/controllers/admin/assessments.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ public function index($iSurveyID)
$this->_delete($iSurveyID, $_POST['id']);

if (Permission::model()->hasSurveyPermission($iSurveyID, 'assessments', 'read')) {
$clang = $this->getController()->lang;

if ($iSurveyID == '') {
show_error($clang->gT("No SID Provided"));
die();
}

$this->_showAssessments($iSurveyID, $sAction, $surveyLanguage, $clang);
$this->_showAssessments($iSurveyID, $sAction, $surveyLanguage);
}

}
Expand All @@ -81,7 +79,7 @@ protected function _renderWrappedTemplate($sAction = 'assessments', $aViewUrls =
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}

private function _showAssessments($iSurveyID, $action, $surveyLanguage, Limesurvey_lang $clang)
private function _showAssessments($iSurveyID, $action)
{
$oAssessments = Assessment::model()->findAllByAttributes(array('sid' => $iSurveyID));
$aData = $this->_collectGroupData($iSurveyID);
Expand All @@ -91,7 +89,7 @@ private function _showAssessments($iSurveyID, $action, $surveyLanguage, Limesurv
$aData['editId'] = '';

if ($action == "assessmentedit" && Permission::model()->hasSurveyPermission($iSurveyID, 'assessments', 'update')) {
$aData = $this->_collectEditData($surveyLanguage, $aData, $clang);
$aData = $this->_collectEditData($aData);
}

$surveyinfo = getSurveyInfo($iSurveyID);
Expand Down Expand Up @@ -125,9 +123,12 @@ private function _collectGroupData($iSurveyID)
return $aData;
}

private function _collectEditData($surveyLanguage, array $aData, Limesurvey_lang $clang)
private function _collectEditData(array $aData)
{
$assessments = Assessment::model()->findAllByAttributes(array('id' => sanitize_int($_POST['id']), 'language' => $surveyLanguage));
$assessments = Assessment::model()->findAllByAttributes(array(
'id' => sanitize_int($_POST['id'])
'language' => App()->language
));

foreach ($assessments as $assessment) {
$editData = $assessment->attributes;
Expand Down
8 changes: 4 additions & 4 deletions application/controllers/admin/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ function addDummies($iSurveyId, $subaction = '')
$aData['thissurvey'] = $thissurvey;
$aData['surveyid'] = $iSurveyId;
$aData['tokenlength'] = $tokenlength;
$aData['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat'],$clang->langcode);
$aData['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat'],App()->language);
$aData['aAttributeFields']=GetParticipantAttributes($iSurveyId);
$this->_renderWrappedTemplate('token', array('tokenbar', 'dummytokenform'), $aData);
}
Expand Down Expand Up @@ -2184,13 +2184,13 @@ function tokenify($iSurveyId)
if($neededtokencount>$newtokencount)
{
$aData['success'] = false;
$message = sprintf($clang->ngT('Only %s token has been created.','Only %s tokens have been created.',$newtokencount),$newtokencount)
.sprintf($clang->ngT('Need %s token.','Need %s tokens.',$neededtokencount),$neededtokencount);
$message = sprintf(ngT('Only %s token has been created.','Only %s tokens have been created.',$newtokencount),$newtokencount)
.sprintf(ngT('Need %s token.','Need %s tokens.',$neededtokencount),$neededtokencount);
}
else
{
$aData['success'] = true;
$message = sprintf($clang->ngT('%s token has been created.','%s tokens have been created.',$newtokencount),$newtokencount);
$message = sprintf(ngT('%s token has been created.','%s tokens have been created.',$newtokencount),$newtokencount);
}
$this->_renderWrappedTemplate('token', array('tokenbar', 'message' => array(
'title' => $clang->gT("Create tokens"),
Expand Down
12 changes: 12 additions & 0 deletions application/core/LSYii_Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,22 @@ public function __construct($config = null)

public function init() {
parent::init();
$this->initLanguage();
// These take care of dynamically creating a class for each token / response table.
Yii::import('application.helpers.ClassFactory');
ClassFactory::registerClass('Token_', 'Token');
ClassFactory::registerClass('Response_', 'Response');
}

public function initLanguage()
{
// Set language to use.
if ($this->request->getParam('lang') !== null)
{
$this->setLanguage($this->request->getParam('lang'));
}

}
/**
* This method handles initialization of the plugin manager
*
Expand Down
1 change: 1 addition & 0 deletions application/extensions/LimeScript/LimeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function run()
$data['urlFormat'] = Yii::app()->urlManager->urlFormat;
$data['adminImageUrl'] = Yii::app()->getConfig('adminimageurl');
$data['csrfToken'] = Yii::app()->request->csrfToken;
$data['language'] = Yii::app()->language;
$data['replacementFields']['path'] = App()->createUrl("admin/limereplacementfields/sa/index/");
$json = json_encode($data, JSON_FORCE_OBJECT);
$script = "LS.data = $json;\n"
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function run($surveyid,$args) {
'refurl' => (($thissurvey['refurl'] == "Y" && isset($_SESSION[$LEMsessid]['refurl'])) ? $_SESSION[$LEMsessid]['refurl'] : NULL),
'savetimings' => ($thissurvey['savetimings'] == "Y"),
'surveyls_dateformat' => (isset($thissurvey['surveyls_dateformat']) ? $thissurvey['surveyls_dateformat'] : 1),
'startlanguage'=>(isset($clang->langcode) ? $clang->langcode : $thissurvey['language']),
'startlanguage'=>(isset(App()->language) ? App()->language : $thissurvey['language']),
'target' => Yii::app()->getConfig('uploaddir').DIRECTORY_SEPARATOR.'surveys'.DIRECTORY_SEPARATOR.$thissurvey['sid'].DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR,
'tempdir' => Yii::app()->getConfig('tempdir').DIRECTORY_SEPARATOR,
'timeadjust' => (isset($timeadjust) ? $timeadjust : 0),
Expand Down
23 changes: 13 additions & 10 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ function eT($string, $escapemode = 'html')
echo gT($string, $escapemode);
}

function ngT($single, $plural, $number, $escapemode = 'html')
function ngT($single, $plural, $number)
{
Yii::import('application.libraries.Limesurvey_lang');
return App()->lang->ngT($single, $plural, $number, $escapemode);
// Temporary fix for old translation styles.
$s = Yii::t('', $single);
$p = Yii::t('', $plural);
return Yii::t('', "$single|$plural", $number);
}

/**
* getQuestionTypeList() Returns list of question types available in LimeSurvey. Edit this if you are adding a new
* question type
Expand Down Expand Up @@ -2400,8 +2403,8 @@ function createTimingsFieldMap($surveyid, $style='full', $force_refresh=false, $
$clang = new Limesurvey_lang($sLanguage);

//checks to see if fieldmap has already been built for this page.
if (isset($timingsFieldMap[$surveyid][$style][$clang->langcode]) && $force_refresh==false) {
return $timingsFieldMap[$surveyid][$style][$clang->langcode];
if (isset($timingsFieldMap[$surveyid][$style][App()->language]) && $force_refresh==false) {
return $timingsFieldMap[$surveyid][$style][App()->language];
}

//do something
Expand All @@ -2425,8 +2428,8 @@ function createTimingsFieldMap($surveyid, $style='full', $force_refresh=false, $
}
}

$timingsFieldMap[$surveyid][$style][$clang->langcode] = $fieldmap;
return $timingsFieldMap[$surveyid][$style][$clang->langcode];
$timingsFieldMap[$surveyid][$style][App()->language] = $fieldmap;
return $timingsFieldMap[$surveyid][$style][App()->language];
}

/**
Expand Down Expand Up @@ -5646,10 +5649,10 @@ function includeKeypad()
$clang = Yii::app()->lang;

Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('third_party').'jquery-keypad/jquery.keypad.min.js');
$localefile = Yii::app()->getConfig('rootdir').'/third_party/jquery-keypad/jquery.keypad-'.$clang->langcode.'.js';
if ($clang->langcode != 'en' && file_exists($localefile))
$localefile = Yii::app()->getConfig('rootdir').'/third_party/jquery-keypad/jquery.keypad-'.App()->language.'.js';
if (App()->language != 'en' && file_exists($localefile))
{
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('third_party').'jquery-keypad/jquery.keypad-'.$clang->langcode.'.js');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('third_party').'jquery-keypad/jquery.keypad-'.App()->language.'.js');
}
Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('third_party') . "jquery-keypad/jquery.keypad.alt.css");
}
Expand Down
20 changes: 10 additions & 10 deletions application/helpers/frontend_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function makegraph($currentstep, $total)
value: '.$size.'
});
;});';
if (getLanguageRTL($clang->langcode))
if (App()->getLocale()->orientation == 'rtl')
{
$graph.='
$(document).ready(function() {
Expand All @@ -165,7 +165,7 @@ function makegraph($currentstep, $total)
<div id="progress-wrapper">
<span class="hide">'.sprintf($clang->gT('You have completed %s%% of this survey'),$size).'</span>
<div id="progress-pre">';
if (getLanguageRTL($clang->langcode))
if (App()->getLocale()->orientation == 'rtl')
{
$graph.='100%';
}
Expand All @@ -177,7 +177,7 @@ function makegraph($currentstep, $total)
$graph.='</div>
<div id="progressbar"></div>
<div id="progress-post">';
if (getLanguageRTL($clang->langcode))
if (App()->getLocale()->orientation == 'rtl')
{
$graph.='0%';
}
Expand Down Expand Up @@ -243,7 +243,7 @@ function makeLanguageChangerSurvey($sSelectedLanguage)
# {
# $sTargetURL=Yii::app()->getController()->createUrl($route."/lang/$sLangCode");
# $aListLang[$sTargetURL]=html_entity_decode($aSurveyLang['nativedescription'], ENT_COMPAT,'UTF-8');
# if($clang->langcode==$sLangCode)
# if(App()->language==$sLangCode)
# $sSelected=$sTargetURL;
# }
}
Expand All @@ -256,8 +256,8 @@ function makeLanguageChangerSurvey($sSelectedLanguage)
{
$aListLang[$sLangCode]=html_entity_decode($aSurveyLang['nativedescription'], ENT_COMPAT,'UTF-8');
}
$sSelected=$clang->langcode;
$sHTMLCode=CHtml::label($clang->gT("Choose another language"), 'lang',array('class'=>'hide label'));
$sSelected=App()->language;
$sHTMLCode=CHtml::label(gT("Choose another language"), 'lang',array('class'=>'hide label'));
$sHTMLCode.=CHtml::dropDownList('lang', $sSelected,$aListLang,array('class'=>$sClass,'data-targeturl'=>$sTargetURL));
// We don't have to add this button if in previewmode
$sHTMLCode.= CHtml::htmlButton($clang->gT("Change the language"),array('type'=>'submit','id'=>"changelangbtn",'value'=>'changelang','name'=>'changelang','class'=>'changelang jshide'));
Expand Down Expand Up @@ -612,7 +612,7 @@ function sendSubmitNotifications($surveyid)

if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['survey_'.$surveyid]['scid']))
{
$aReplacementVars['RELOADURL']="".Yii::app()->getController()->createUrl("/survey/index/sid/{$surveyid}/loadall/reload/scid/".$_SESSION['survey_'.$surveyid]['scid']."/loadname/".urlencode($_SESSION['survey_'.$surveyid]['holdname'])."/loadpass/".urlencode($_SESSION['survey_'.$surveyid]['holdpass'])."/lang/".urlencode($clang->langcode));
$aReplacementVars['RELOADURL']="".Yii::app()->getController()->createUrl("/survey/index/sid/{$surveyid}/loadall/reload/scid/".$_SESSION['survey_'.$surveyid]['scid']."/loadname/".urlencode($_SESSION['survey_'.$surveyid]['holdname'])."/loadpass/".urlencode($_SESSION['survey_'.$surveyid]['holdpass'])."/lang/".urlencode(App()->language));
if ($bIsHTML)
{
$aReplacementVars['RELOADURL']="<a href='{$aReplacementVars['RELOADURL']}'>{$aReplacementVars['RELOADURL']}</a>";
Expand Down Expand Up @@ -839,8 +839,8 @@ function buildsurveysession($surveyid,$preview=false)
//global $surveyid;
global $move, $rooturl;

$clang = Yii::app()->lang;
$sLangCode=$clang->langcode;

$sLangCode=App()->language;
$languagechanger=makeLanguageChangerSurvey($sLangCode);
if(!$preview)
$preview=Yii::app()->getConfig('previewmode');
Expand Down Expand Up @@ -2198,7 +2198,7 @@ function display_first_page() {
// Fill some necessary var for template
$navigator = surveymover();
$sitename = Yii::app()->getConfig('sitename');
$languagechanger=makeLanguageChangerSurvey($clang->langcode);
$languagechanger=makeLanguageChangerSurvey(App()->language);

sendCacheHeaders();
doHeader();
Expand Down
Loading

0 comments on commit c772cd1

Please sign in to comment.