surveyjs / survey-creator

Scalable open-source survey software to generate dynamic JSON-driven forms within your JavaScript application. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
https://surveyjs.io/open-source
Other
923 stars 377 forks source link

How to add languages in multiple language support? supportedLanguages doesn't work #847

Open AshwinTayson opened 4 years ago

AshwinTayson commented 4 years ago

Are you requesting a feature, reporting a bug or ask a question?

Both. How do I add a language which is not in the list? and setting the supported locales for the editor doesn't work.

What is the current behavior?

Survey.surveyLocalization.supportedLocales = ["en", "de", 'fr'];

Currently all languages are shown.

What is the expected behavior?

Should give a survey creator with only English, Espanol, French Languages.

How would you reproduce the current behavior (if this is a bug)?

In survey-react package with the following code I'm facing the bug

Provide the test code and the tested page URL (if applicable)

import React, { useState, useEffect } from "react";
import * as SurveyJSCreator from "survey-creator";
import * as Survey from "survey-react";

SurveyJSCreator.StylesManager.applyTheme("default");
Survey.surveyLocalization.supportedLocales = ["en", "de", 'fr'];

const SurveyCreator = () => {

  const [surveyCreator, setSurveyCreator] = useState();

  useEffect(() => {
    let options = {
      questionTypes: [
        "text",
        "checkbox",
        "radiogroup",
        "dropdown",
        "comment",
        "boolean",
      ],
      pageEditMode: "single",
      showTranslationTab: true
    };
    setSurveyCreator(new SurveyJSCreator.SurveyCreator(
      null,
      options
    ));
  }, []);

  useEffect(() => {
    if (surveyCreator) {
      console.log(Survey.surveyLocalization.getLocales())
      surveyCreator.render("surveyCreatorContainer");
      surveyCreator.showToolbox = "right";
      surveyCreator.showPropertyGrid = "right";
      surveyCreator.rightContainerActiveItem("toolbox");
    }

  }, [surveyCreator])

  return (
    <div>
      <div id="surveyCreatorContainer" />
    </div>
  );
}

export default SurveyCreator;

Specify your

andrewtelnov commented 4 years ago

@AshwinTayson You don't need this import on this page: import * as Survey from "survey-react"; I believe you have SurveyKO alias for "survey-knockout", please use this line: SurveyKO.surveyLocalization.supportedLocales = ["en", "de", 'fr'];

You are limited locales in the SurveyJS instance that you do not use on this page. SurveyJS Creator use "survey-knockout".

Thank you, Andrew

AshwinTayson commented 4 years ago

How do I add my own languages?

andrewtelnov commented 4 years ago

@AshwinTayson It describes in readme files, for library and for creator.

Thank you, Andrew