Question T2206
Visible to All Users

Get translated languages from quest Json

created 6 years ago (modified 6 years ago)

How can I get translated languages from answer saved as Json.
When editor saves questions, I would like to know what languages are available for this quest.
For example, I got language code array like this
["en", "jp"].

Can I extract it from quest Json ? or Can I get it when query editor saves?

Answers approved by surveyjs Support

created 6 years ago

Hello,
Do you want to make it from the code or from UI?
If you want to do it from UI, then there is a translation tab. You can see it on our survey creator page. You may choose here a language and export to "csv" format.

Thank you,
Andrew
SurveyJS Team

    Show previous comments (2)

      I am using surveyjs in react.js
      I tried your example like this

      import * as Survey from "survey-react";
      import * as SurveyCreator from "survey-creator";
      import * as SurveyJSEditor from "surveyjs-editor";

      class SurveyEditor extends Component {
      editor;
      componentDidMount() {
      let editorOptions = {
      questionTypes : ["text", "checkbox", "radiogroup", "dropdown"],
      showEmbededSurveyTab: true,
      showJSONEditorTab: false,
      showEmbededSurveyTab: false,
      showTranslationTab: true,
      isAutoSave: true
      };
      this.editor = new SurveyJSEditor.SurveyEditor(
      "surveyEditorContainer",
      editorOptions
      );
      this.editor.saveSurveyFunc = this.saveSurveyFunc;
      this.editor.text = this.props.surveyQuestion
      }
      saveSurveyFunc = () => {
      var survey = new Survey.Survey(this.editor.text);
      var translation = new SurveyCreator.Translation(survey);
      var arrayOfAllUsedLocates = translation.koLocales();
      console.log(arrayOfAllUsedLocates)
      }
      render() {
      return <div id="surveyEditorContainer" style={{
      minWidth: 1000
      }}/>;
      }

      }

      I got this error Error: Component survey is already registered

      Would you please let me know what's wrong with my code?
      Thanks

        You have to use creator or editor.
        If you have already SurveyJS Editor (we renamed it into creator) then in your code you just call:

        JavaScript
        this.editor.translation.survey = this.editor.survey; var arrayOfAllUsedLocates =this.editor.translation.koLocales(); console.log(arrayOfAllUsedLocates)

        Thank you,
        Andrew
        SurveyJS Team

          It works!
          Thanks