Skip to content

Commit 387bb36

Browse files
committed
2 parents d79321d + 108e4df commit 387bb36

File tree

3 files changed

+110
-15
lines changed

3 files changed

+110
-15
lines changed

config.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,38 @@
115115
"repeatable": false,
116116
"default": ""
117117
},
118+
{
119+
"key": "hide-answers-without-translation",
120+
"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)",
121+
"required": false,
122+
"type": "checkbox",
123+
"repeatable": false,
124+
"default": ""
125+
},
126+
{
127+
"key": "hide-matrix-questions-without-translation",
128+
"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)",
129+
"required": false,
130+
"type": "checkbox",
131+
"repeatable": false,
132+
"default": ""
133+
},
134+
{
135+
"key": "hide-answers-without-translation-survey",
136+
"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)",
137+
"required": false,
138+
"type": "checkbox",
139+
"repeatable": false,
140+
"default": ""
141+
},
142+
{
143+
"key": "hide-matrix-questions-without-translation-survey",
144+
"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)",
145+
"required": false,
146+
"type": "checkbox",
147+
"repeatable": false,
148+
"default": ""
149+
},
118150
{
119151
"key": "multilingual-econsent",
120152
"name": "Use multilingual PDFs for eConsent/survey download",

js/multilingual.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
var translations = {};
1818
var errorChecking = 0;
1919
var anyTranslated = false;
20+
var matrixProcessed = {};
2021

2122
//document ready change language
2223
$( document ).ready(function(){
@@ -130,6 +131,18 @@
130131
var id;
131132
for(id in translations['questions']){
132133
if(translations['questions'][id]['matrix'] != null){
134+
if(!(translations['questions'][id]['matrix'] in matrixProcessed) && settings['hide-matrix-questions-without-translation']['value']) {
135+
$('tr[mtxgrp="'+translations['questions'][id]['matrix']+'"].mtxfld').each(function(){
136+
var curMtxQuestionId = $(this).attr('id');
137+
curMtxQuestionId = curMtxQuestionId.replace('-tr', '');
138+
if(typeof translations['questions'][curMtxQuestionId] == 'undefined') {
139+
$(this).hide();
140+
} else {
141+
$(this).show();
142+
}
143+
});
144+
matrixProcessed[translations['questions'][id]['matrix']] = true;
145+
}
133146
$('#' + id + '-tr').children().children().children().children().children().children().children().children().children().children('td:first').html(translations['questions'][id]['text']);
134147
}
135148
else if(translations['questions'][id]['type'] == 'descriptive'){
@@ -149,8 +162,12 @@
149162
var id2;
150163
for(id2 in translations['answers'][id]['text']){
151164
$('[name="' + id + '"] option').each(function(){
165+
$(this).show();
152166
if($(this).val() == id2){
153167
$(this).text(translations['answers'][id]['text'][id2]);
168+
$(this).data('lang', lang);
169+
} else if(settings['hide-answers-without-translation']['value'] && $(this).val() !== '' && $(this).data('lang') !== lang) {
170+
$(this).hide();
154171
}
155172
});
156173
}
@@ -177,19 +194,29 @@
177194
var id2;
178195
for(id2 in translations['answers'][id]['text']){
179196
$('[name="' + id + '___radio"]').each(function(){
197+
$(this).parent().contents().last().show();
198+
$(this).show();
180199
if($(this).val() == id2){
181-
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
182200
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
201+
$(this).data('lang', lang);
202+
} else if(settings['hide-answers-without-translation']['value'] && $(this).data('lang') !== lang) {
203+
$(this).parent().contents().last().hide();
204+
$(this).hide();
183205
}
184206
});
185207
}
186208
}
187209
else if(translations['answers'][id]['type'] == 'checkbox'){
188210
var id2;
189211
for(id2 in translations['answers'][id]['text']){
190-
$('[name="__chk__' + id + '_RC_' + id2 + '"]').each(function(){
191-
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
192-
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
212+
$('#'+id+'-tr .choicevert').each(function(){
213+
$(this).show();
214+
if($(this).find('[name="__chk__' + id + '_RC_' + id2 + '"]').length) {
215+
$(this).contents().last().html(' ' + translations['answers'][id]['text'][id2]);
216+
$(this).data('lang', lang);
217+
} else if(settings['hide-answers-without-translation']['value'] && $(this).data('lang') !== lang) {
218+
$(this).hide();
219+
}
193220
});
194221
}
195222
}
@@ -285,6 +312,7 @@
285312
translations = r;
286313
langReady = 1;
287314
anyTranslated = true;
315+
matrixProcessed = {};
288316
}
289317
},
290318
error: function(jqXHR, textStatus, errorThrown) {

js/multilingual_survey.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
var translations = {};
1818
var errorChecking = 0;
1919
var anyTranslated = false;
20+
var matrixProcessed = {};
2021

2122
//document ready change language
2223
$( document ).ready(function(){
@@ -530,18 +531,28 @@
530531
var id;
531532
for(id in translations['questions']){
532533
if(translations['questions'][id]['matrix'] != null){
534+
if(!(translations['questions'][id]['matrix'] in matrixProcessed) && settings['hide-matrix-questions-without-translation-survey']['value']) {
535+
$('tr[mtxgrp="'+translations['questions'][id]['matrix']+'"].mtxfld').each(function(){
536+
var curMtxQuestionId = $(this).attr('id');
537+
curMtxQuestionId = curMtxQuestionId.replace('-tr', '');
538+
if(typeof translations['questions'][curMtxQuestionId] == 'undefined') {
539+
$(this).hide();
540+
} else {
541+
$(this).show();
542+
}
543+
});
544+
matrixProcessed[translations['questions'][id]['matrix']] = true;
545+
}
533546
//$('#' + id + '-tr').children('td').eq(1).children('table').children().children().children('td:first').html(translations['questions'][id]['text']);
534547
$('#label-' + id).html(translations['questions'][id]['text']);
535-
}
536-
else if(translations['questions'][id]['type'] == 'descriptive'){
548+
} else if(translations['questions'][id]['type'] == 'descriptive'){
537549
var tmp = $('#' + id + '-tr').children('td').eq(1).html();
538550
if(tmp != undefined){
539551
$('#' + id + '-tr').children('td').eq(1).html(translations['questions'][id]['text']);
540552
//tmp = tmp.split(/<(.+)/);
541553
//$('#' + id + '-tr').children('td').eq(1).html(translations['questions'][id]['text'] + ' <' + tmp[1]);
542554
}
543-
}
544-
else{
555+
} else {
545556
$('#label-' + id).html(translations['questions'][id]['text']);
546557
}
547558
}
@@ -552,8 +563,12 @@
552563
var id2;
553564
for(id2 in translations['answers'][id]['text']){
554565
$('[name="' + id + '"] option').each(function(){
566+
$(this).show();
555567
if($(this).val() == id2){
556568
$(this).text(translations['answers'][id]['text'][id2]);
569+
$(this).data('lang', lang);
570+
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).val() !== '' && $(this).data('lang') !== lang) {
571+
$(this).hide();
557572
}
558573
});
559574
}
@@ -581,43 +596,62 @@
581596
//translations['answers'][id]['text'][id2]);
582597
//$('#' + translations['answers'][id]['matrix'] + '-mtxhdr-tr').children('td').eq(1).children().children().children().children('td').eq(counter).html(translations['answers'][id]['text'][id2]);
583598
$('#matrixheader-' + translations['answers'][id]['matrix'] + '-' + id2).html(translations['answers'][id]['text'][id2]);
599+
// $('#matrixheader-' + translations['answers'][id]['matrix'] + '-' + id2).html('Answer');
584600
counter++;
585601
}
586602
}
587603
else if(translations['answers'][id]['type'] == 'radio' || translations['answers'][id]['type'] == 'yesno' || translations['answers'][id]['type'] == 'truefalse'){
588604
var id2;
589605
for(id2 in translations['answers'][id]['text']){
590606
$('[name="' + id + '___radio"]').each(function(){
607+
$(this).parent().contents().last().show();
608+
$(this).show();
591609
if($(this).val() == id2){
592-
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
593610
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
611+
$(this).data('lang', lang);
612+
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
613+
$(this).parent().contents().last().hide();
614+
$(this).hide();
594615
}
595616
});
596617
}
597618
//enhanced radio buttons
598619
for(id2 in translations['answers'][id]['text']){
599620
$('.ec').each(function(){
600621
var tmp = $(this).parent().attr('comps').split(',');
601-
if(tmp[0] == id && tmp[2] == id2){
602-
$(this).html(translations['answers'][id]['text'][id2]);
622+
$(this).show();
623+
if(tmp[0] == id && tmp[2] == id2) {
624+
$(this).html(' ' + translations['answers'][id]['text'][id2]);
625+
$(this).data('lang', lang);
626+
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
627+
$(this).hide();
603628
}
604629
});
605630
}
606631
}
607632
else if(translations['answers'][id]['type'] == 'checkbox'){
608633
var id2;
609634
for(id2 in translations['answers'][id]['text']){
610-
$('[name="__chk__' + id + '_RC_' + id2 + '"]').each(function(){
611-
//$(this).parent().contents().last().replaceWith(' ' + translations['answers'][id]['text'][id2]);
612-
$(this).parent().contents().last().html(' ' + translations['answers'][id]['text'][id2]);
635+
$('#'+id+'-tr .choicevert').each(function(){
636+
$(this).show();
637+
if($(this).find('[name="__chk__' + id + '_RC_' + id2 + '"]').length) {
638+
$(this).contents().last().html(' ' + translations['answers'][id]['text'][id2]);
639+
$(this).data('lang', lang);
640+
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
641+
$(this).hide();
642+
}
613643
});
614644
}
615645
//enhanced checkboxes
616646
for(id2 in translations['answers'][id]['text']){
617647
$('.ec').each(function(){
618648
var tmp = $(this).parent().attr('comps').split(',');
619-
if(tmp[0] == id && tmp[2] == id2){
649+
$(this).show();
650+
if(tmp[0] == id && tmp[2] == id2) {
620651
$(this).html(translations['answers'][id]['text'][id2]);
652+
$(this).data('lang', lang);
653+
} else if(settings['hide-answers-without-translation-survey']['value'] && $(this).data('lang') !== lang) {
654+
$(this).hide();
621655
}
622656
});
623657
}
@@ -786,6 +820,7 @@
786820
translations = r;
787821
langReady = 1;
788822
anyTranslated = true;
823+
matrixProcessed = {};
789824
}
790825
},
791826
error: function(jqXHR, textStatus, errorThrown) {

0 commit comments

Comments
 (0)