Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
smartinkc committed Feb 26, 2020
2 parents d79321d + 108e4df commit 387bb36
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 15 deletions.
32 changes: 32 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@
"repeatable": false,
"default": ""
},
{
"key": "hide-answers-without-translation",
"name": "Hide Answers that do not have a translation on instruments. (Radio/Dropdown/Checkbox Options without a translation for the current language will not be displayed)",
"required": false,
"type": "checkbox",
"repeatable": false,
"default": ""
},
{
"key": "hide-matrix-questions-without-translation",
"name": "Hide Matrix Field Questions that do not have a translation on instruments. (Matrix Rows/Questions without a translation for the current language will not be displayed)",
"required": false,
"type": "checkbox",
"repeatable": false,
"default": ""
},
{
"key": "hide-answers-without-translation-survey",
"name": "Hide Answers that do not have a translation on surveys. (Radio/Dropdown/Checkbox Options without a translation for the current language will not be displayed)",
"required": false,
"type": "checkbox",
"repeatable": false,
"default": ""
},
{
"key": "hide-matrix-questions-without-translation-survey",
"name": "Hide Matrix Field Questions that do not have a translation on surveys. (Matrix Rows/Questions without a translation for the current language will not be displayed)",
"required": false,
"type": "checkbox",
"repeatable": false,
"default": ""
},
{
"key": "multilingual-econsent",
"name": "Use multilingual PDFs for eConsent/survey download",
Expand Down
36 changes: 32 additions & 4 deletions js/multilingual.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var translations = {};
var errorChecking = 0;
var anyTranslated = false;
var matrixProcessed = {};

//document ready change language
$( document ).ready(function(){
Expand Down Expand Up @@ -130,6 +131,18 @@
var id;
for(id in translations['questions']){
if(translations['questions'][id]['matrix'] != null){
if(!(translations['questions'][id]['matrix'] in matrixProcessed) && settings['hide-matrix-questions-without-translation']['value']) {
$('tr[mtxgrp="'+translations['questions'][id]['matrix']+'"].mtxfld').each(function(){
var curMtxQuestionId = $(this).attr('id');
curMtxQuestionId = curMtxQuestionId.replace('-tr', '');
if(typeof translations['questions'][curMtxQuestionId] == 'undefined') {
$(this).hide();
} else {
$(this).show();
}
});
matrixProcessed[translations['questions'][id]['matrix']] = true;
}
$('#' + id + '-tr').children().children().children().children().children().children().children().children().children().children('td:first').html(translations['questions'][id]['text']);
}
else if(translations['questions'][id]['type'] == 'descriptive'){
Expand All @@ -149,8 +162,12 @@
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="' + id + '"] option').each(function(){
$(this).show();
if($(this).val() == id2){
$(this).text(translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation']['value'] && $(this).val() !== '' && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
Expand All @@ -177,19 +194,29 @@
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="' + id + '___radio"]').each(function(){
$(this).parent().contents().last().show();
$(this).show();
if($(this).val() == id2){
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation']['value'] && $(this).data('lang') !== lang) {
$(this).parent().contents().last().hide();
$(this).hide();
}
});
}
}
else if(translations['answers'][id]['type'] == 'checkbox'){
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="__chk__' + id + '_RC_' + id2 + '"]').each(function(){
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$('#'+id+'-tr .choicevert').each(function(){
$(this).show();
if($(this).find('[name="__chk__' + id + '_RC_' + id2 + '"]').length) {
$(this).contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation']['value'] && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
}
Expand Down Expand Up @@ -285,6 +312,7 @@
translations = r;
langReady = 1;
anyTranslated = true;
matrixProcessed = {};
}
},
error: function(jqXHR, textStatus, errorThrown) {
Expand Down
57 changes: 46 additions & 11 deletions js/multilingual_survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var translations = {};
var errorChecking = 0;
var anyTranslated = false;
var matrixProcessed = {};

//document ready change language
$( document ).ready(function(){
Expand Down Expand Up @@ -530,18 +531,28 @@
var id;
for(id in translations['questions']){
if(translations['questions'][id]['matrix'] != null){
if(!(translations['questions'][id]['matrix'] in matrixProcessed) && settings['hide-matrix-questions-without-translation-survey']['value']) {
$('tr[mtxgrp="'+translations['questions'][id]['matrix']+'"].mtxfld').each(function(){
var curMtxQuestionId = $(this).attr('id');
curMtxQuestionId = curMtxQuestionId.replace('-tr', '');
if(typeof translations['questions'][curMtxQuestionId] == 'undefined') {
$(this).hide();
} else {
$(this).show();
}
});
matrixProcessed[translations['questions'][id]['matrix']] = true;
}
//$('#' + id + '-tr').children('td').eq(1).children('table').children().children().children('td:first').html(translations['questions'][id]['text']);
$('#label-' + id).html(translations['questions'][id]['text']);
}
else if(translations['questions'][id]['type'] == 'descriptive'){
} else if(translations['questions'][id]['type'] == 'descriptive'){
var tmp = $('#' + id + '-tr').children('td').eq(1).html();
if(tmp != undefined){
$('#' + id + '-tr').children('td').eq(1).html(translations['questions'][id]['text']);
//tmp = tmp.split(/<(.+)/);
//$('#' + id + '-tr').children('td').eq(1).html(translations['questions'][id]['text'] + ' <' + tmp[1]);
}
}
else{
} else {
$('#label-' + id).html(translations['questions'][id]['text']);
}
}
Expand All @@ -552,8 +563,12 @@
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="' + id + '"] option').each(function(){
$(this).show();
if($(this).val() == id2){
$(this).text(translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).val() !== '' && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
Expand Down Expand Up @@ -581,43 +596,62 @@
//translations['answers'][id]['text'][id2]);
//$('#' + translations['answers'][id]['matrix'] + '-mtxhdr-tr').children('td').eq(1).children().children().children().children('td').eq(counter).html(translations['answers'][id]['text'][id2]);
$('#matrixheader-' + translations['answers'][id]['matrix'] + '-' + id2).html(translations['answers'][id]['text'][id2]);
// $('#matrixheader-' + translations['answers'][id]['matrix'] + '-' + id2).html('Answer');
counter++;
}
}
else if(translations['answers'][id]['type'] == 'radio' || translations['answers'][id]['type'] == 'yesno' || translations['answers'][id]['type'] == 'truefalse'){
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="' + id + '___radio"]').each(function(){
$(this).parent().contents().last().show();
$(this).show();
if($(this).val() == id2){
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
$(this).parent().contents().last().hide();
$(this).hide();
}
});
}
//enhanced radio buttons
for(id2 in translations['answers'][id]['text']){
$('.ec').each(function(){
var tmp = $(this).parent().attr('comps').split(',');
if(tmp[0] == id && tmp[2] == id2){
$(this).html(translations['answers'][id]['text'][id2]);
$(this).show();
if(tmp[0] == id && tmp[2] == id2) {
$(this).html(' ' + translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
}
else if(translations['answers'][id]['type'] == 'checkbox'){
var id2;
for(id2 in translations['answers'][id]['text']){
$('[name="__chk__' + id + '_RC_' + id2 + '"]').each(function(){
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$('#'+id+'-tr .choicevert').each(function(){
$(this).show();
if($(this).find('[name="__chk__' + id + '_RC_' + id2 + '"]').length) {
$(this).contents().last().html(' ' + translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
//enhanced checkboxes
for(id2 in translations['answers'][id]['text']){
$('.ec').each(function(){
var tmp = $(this).parent().attr('comps').split(',');
if(tmp[0] == id && tmp[2] == id2){
$(this).show();
if(tmp[0] == id && tmp[2] == id2) {
$(this).html(translations['answers'][id]['text'][id2]);
$(this).data('lang', lang);
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
$(this).hide();
}
});
}
Expand Down Expand Up @@ -786,6 +820,7 @@
translations = r;
langReady = 1;
anyTranslated = true;
matrixProcessed = {};
}
},
error: function(jqXHR, textStatus, errorThrown) {
Expand Down

0 comments on commit 387bb36

Please sign in to comment.