Is there a way to display answers in alphabetical order for all translations? | XM Community
Solved

Is there a way to display answers in alphabetical order for all translations?

  • 28 November 2018
  • 10 replies
  • 319 views

The question Which country are you from? is alphabetized in English however when i look at the German or Dutch translations it looks a bit weird not starting with an A.
Is there any way you can display the order of answers differently per language?
Thank you
icon

Best answer by TomG 28 November 2018, 13:07

View original

10 replies

Userlevel 7
Badge +27
You could duplicate the question, arrange the duplicate in German/Dutch alphabetical order, then use display logic to display the original question in English and the duplicate in German/Dutch. Your answers will be in two different questions in your data, so you could add a bit of survey flow logic to combine them in one embedded data variable.

Another way to do it would be to use JavaScript to sort the list on the fly.
Ok thanks , indeed duplicating would be less ideal. I'm not a Java expert though, is there a peace of code that i can copy in?
Userlevel 7
Badge +27
> @Ingrid said:
> Ok thanks , indeed duplicating would be less ideal. I'm not a Java expert though, is there a peace of code that i can copy in?

No, there isn't any code I'm aware of that you could copy. The JS would be fairly complex.
> @Ingrid said:
> Ok thanks , indeed duplicating would be less ideal. I'm not a Java expert though, is there a peace of code that i can copy in?

Did you happen to find a solution for this or develop JS? I'm working on a survey with over 10 translations so different versions of each would not be ideal at all.
Badge +1

https://www.qualtrics.com/community/discussion/comment/23399#Comment_23399JodieG hi, I'm also implementing a survey in 10 languages. Were you able to resolve this for the 10 translations?

https://www.qualtrics.com/community/discussion/comment/23399#Comment_23399The following JavaScript worked for me. It will grab the language currently selected in Qualtrics by the survey respondent and works with single choice, multiple answer, dropdowns, and select boxes.

/* Tweak to ensure dropdowns are sorted in other languages */
// Pull choices from current question
let targetElement = this.getChoiceContainer();
let myChoices = targetElement.children;
myChoices = Array.prototype.slice.call(myChoices);

// Sort choices
myChoices.sort(function(a, b) {
return a.textContent.localeCompare(b.textContent, '${e://Field/Q_Language}', {sensitivity: 'base', ignorePunctuation: true, numeric: true});
});

// Return choices to current question
for (let i=0; i < myChoices.length; i++) {
targetElement.appendChild(myChoices[i]);
}

Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/33043#Comment_33043It's fine if you only want to sort French.
Since the original post several months ago, I've written a JS function that provides a more robust solution (not free). It alphabetizes multiple choice questions (vertical single answer, vertical multi-answer, dropdown list, select box and multi-select box) on-the-fly based on the current language. It also supports anchored choices.
If anyone is interested, feel free to contact me by private message.

https://www.qualtrics.com/community/discussion/comment/33045#Comment_33045Hey Tom, good point. I make a tweak to the above so it works with the language currently selected in Qualtrics by the survey respondent.

Badge +1

https://www.qualtrics.com/community/discussion/comment/23399#Comment_23399The following JavaScript worked for me. It will grab the language currently selected in Qualtrics by the survey respondent and works with single choice, multiple answer, dropdowns, and select boxes.

/* Tweak to ensure dropdowns are sorted in other languages */
// Pull choices from current question
let targetElement = this.getChoiceContainer();
let myChoices = targetElement.children;
myChoices = Array.prototype.slice.call(myChoices);

// Sort choices
myChoices.sort(function(a, b) {
return a.textContent.localeCompare(b.textContent, '${e://Field/Q_Language}', {sensitivity: 'base', ignorePunctuation: true, numeric: true});
});

// Return choices to current question
for (let i=0; i < myChoices.length; i++) {
targetElement.appendChild(myChoices[i]);
}

wow, this worked amazingly well - thank you for sharing!

one question: is there a way to exclude answer options like ‘other’ or ‘none of these’ from the sorting? I appreciate any leads :)

Userlevel 7
Badge +27

@EvaZw - The mcAlphabetize function supports anchored choices. It also works with all languages, which is not the case with the code above.

Leave a Reply