Translation for Matrix table header applied through JavaScript | XM Community
Skip to main content

I used the following JS code to add heading to the statements column in a matrix table question since there is no native function. However, I will be translating the survey into multiple language. Is there any way using the Q_lang variable to show the heading according to the language selected?
 

jQuery("#"+this.questionId+" td.c1:first").html("Label Text");

  

Create a multiple choice question where the choices are the items you want to translate. Hide the question with survey flow or display logic. Translate the question choices.  Pipe the appropriate choice text into your JavaScript.


Create a multiple choice question where the choices are the items you want to translate. Hide the question with survey flow or display logic. Translate the question choices.  Pipe the appropriate choice text into your JavaScript.

That's an excellent suggestion Tom.

I was able to work out something similar. I created a "lang” variable for language and and set branch logic based on the language. (e.g, if Q_lang=Es then lang = spanish). And use the following code.

  var questionId = this.questionId;

/* Get the value of the embedded data field "language" */
var lang = "${e://Field/lang}";

/* Define your language-specific labels */
var labelEnglish = "Label Text";
var labelSpanish = "Texto de Etiqueta"; // Example Spanish translation

/* Determine which label to apply based on the language */
var labelToShow = labelEnglish; // Default to English

if (lang === "spanish") {
labelToShow = labelSpanish;
}
// You can add more 'else if' conditions for other languages

/* Apply the label to the first cell of the statements column */
jQuery("#" + questionId + " td.c1:first").html(labelToShow);
});

But I like your suggestion better since that way I can have the heading text in the overlays as well.

I can make a hidden question and apply display logic on options using the same logic I did for the lang variable. And then pipe the display logic.

Let me know if you're able to update the JS that I provided to pipe in the displayed option from the hidden question 


@mugheeshay,

If you follow my approach the JavaScript is:

jQuery("#" + questionId + " td.c1:first").html("${q://QIDx/ChoiceDescription/1}");

Where QIDx is the hidden question and 1 is the first choice in the hidden question.  You only need to hide the question, you don’t need display logic on the choices. I usually put the hidden question in a block by itself under a false branch at the beginning of the survey flow. That way you don’t need any logic on the question itself.


Leave a Reply