localizationsurveyjs

How to localize multiple choice questions in SurveyJS?


I use SurveyJS to run surveys. I read the example on localization and implemented it. I can localize a title with:

"title": {
  "default": "During the past week ...",
  "de-de": "In der letzten Woche ...",
}

and the same format works for "text", "labelTrue" and "labelFalse".

So I try that format with multiple choice questions:

{
    "type": "radiogroup",
    "name": "parent_type",
    "title": {
      "default": "I am...",
      "de-de": "Sie sind:",
    },
    "isRequired": true,
    "showOtherItem": true,
    "colCount": 1,
    "choices": {
      "default": ["mother", "father"],
      "de-de": ["Mutter", "Vater"],
    },
    "separateSpecialChoices": true,
    "showClearButton": true,
  }

and I get the error in the browser JavaScript console:

Uncaught TypeError: this.getFilteredChoices(...).slice is not a function

I also tried reversing the table-dictionary order:

{
    "type": "radiogroup",
    "name": "parent_type",
    "title": {
      "default": "I am:",
      "de-de": "Sie sind:",
    },
    "isRequired": true,
    "showOtherItem": true,
    "colCount": 1,
    "choices": [{
      "default": "mother",
      "de-de": "Mutter",
    }, {
      "default": "father",
      "de-de": "Vater"
    }],
    "separateSpecialChoices": true,
    "showClearButton": true,
  }

This shows the survey but the answers look like:

I am:   *

- [object Object]

- [object Object]

- Other (describe):

I cannot use a boolean type because sometimes a grandmother or uncle answers the survey. For now, I've been localizing the title of the question instead with "Sie Sind: (mother = Mutter, father = Vater)", but it looks bad and decreases the likelihood of an answer.

How can I localize a multiple-choice question in SurveyJS?


Solution

  • I believe with choices the objective is to have a single value for each choice but just a different display text. This should work:

    {
        "type": "radiogroup",
        "name": "parent_type",
        "title": {
          "default": "I am...",
          "de-de": "Sie sind:",
        },
        "isRequired": true,
        "showOtherItem": true,
        "colCount": 1,
        "choices": [
           {
              "value": "mother",
              "text": { "default": "Mother", "de-de": "Mutter" }
           },
           {
              "value": "father",
              "text": { "default": "Father", "de-de": "Vater" }
           }
        ],
        "separateSpecialChoices": true,
        "showClearButton": true,
      }
    

    Or if you want to specify multiple languages without a default:

    {
       //...
        "choices": [
           {
              "value": "mother",
              "text": { "en": "Mother", "de-de": "Mutter" }
           },
           {
              "value": "father",
              "text": { "en": "Father", "de-de": "Vater" }
           }
        ],
       //..
    }