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
919 stars 373 forks source link

Localized Survey Creator - The survey doesn't contain visible pages - The message appears is translated in design mode but untranslated in preview #4923

Closed JaneSjs closed 12 months ago

JaneSjs commented 1 year ago

User Issue: T15707 - Missing localization for Preview tab text - no pages or questions https://surveyjs.answerdesk.io/internal/ticket/details/T15707


When a survey is empty, it should use the same locale as it is defined for a Survey Creator. Otherwise, the 'a survey is empty' message appears untranslated: image

JaneSjs commented 1 year ago

This message is defined within a Form Library localization: emptySurvey. When a survey creator appears at design time, an empty survey content follows a survey creator localization and translates the empty survey message. However, when a user switches to the preview mode, a survey uses its own locale property value.

You can handle a preview survey creation using the creator.onSurveyInstanceCreated event. If a survey is empty, change it's locale to the currently used creator locale.

creator.locale = "fr";
creator.onSurveyInstanceCreated.add((sender, options) => {
    if (options.reason === "test" && options.survey.isEmpty) {
      options.survey.locale = creator.locale;
    }
});

View CodeSandbox

andrewtelnov commented 12 months ago

@JaneSjs Yes, the user should set the survey locale to the needed locale.

Thank you, Andrew