How to change Survey Creator default language ?
Change language
Answers approved by surveyjs Support
Hello,
I guess. you have already changed it: SurveyCreator.editorLocalization.currentLocale = "fr";
.
Do you want to change the default language for all surveys? Then you can use the following code:
JavaScriptSurvey.surveyLocalization.defaultLocale = "fr";
Thank you,
Andrew
SurveyJS Team
Other Answers
I tried both solutions but the default language remains the same (english) in dropdown list
Comments
(3)
NT
3 years ago
Here is my code. It still does not work
JavaScriptimport React, { useEffect, useRef, useState } from 'react'
import * as Survey from "survey-react/survey.react.min.js";
import * as SurveyCreator from "survey-creator/survey-creator.min.js";
import * as SurveyAnalytics from "survey-analytics/survey.analytics.min.js";
import "survey-creator/survey-creator.min.css";
import "survey-react/modern.min.css";
import "survey-analytics/survey.analytics.min.css";
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faDesktop, faMobileAlt } from '@fortawesome/free-solid-svg-icons';
import Switch from "react-switch";
Survey.StylesManager.applyTheme("modern");
SurveyCreator.StylesManager.applyTheme("modern");
Survey.surveyLocalization.defaultLocale = "fr";
const myloc = Survey.surveyLocalization.getCurrentStrings();
console.log(SurveyCreator.editorLocalization)
myloc.completingSurvey = "Merci d’avoir répondu à notre enquête !"
const mycustomSurveyStrings = {
pagePrevText: "Précédent",
pageNextText: "Suivant",
completeText: "Terminer"
};
Survey
.surveyLocalization
.locales["fr"] = mycustomSurveyStrings;
Survey.Serializer.findProperty("survey", "title").visible = true;
Survey.Serializer.findProperty("survey", "title").value = 'TEST';
Survey.Serializer.findProperty("survey", "description").visible = false;
Survey.Serializer.findProperty("survey", "showTitle").visible = false;
export const SurveyBuilder = (props) => {
const { json, save } = props
const ref = useRef(null)
useEffect(() => {
let creatorOptions = {
questionTypes: ["text", "checkbox", "radiogroup", "dropdown", "rating", "comment"]
};
Survey.surveyLocalization.defaultLocale = "fr";
SurveyCreator.localization.currentLocale = "fr";
ref.current = new SurveyCreator.SurveyCreator(null, creatorOptions);
console.log(ref.current)
ref.current.showToolbox = "left";
ref.current.showJSONEditorTab = false
ref.current.showPropertyGrid = "left";
ref.current.rightContainerActiveItem("toolbox");
ref.current.showSurveyTitle = 'always'
ref.current.allowControlSurveyTitleVisibility = false
ref.current.isAutoSave = false
ref.current.completedHtml = "JOEL"
console.log(ref.current)
if (json)
ref.current.JSON = JSON.parse(json)
//Add all countries question into toolbox
// creator.toolbox.addItem({
// name: "countries",
// isCopied: true,
// iconName: "icon-default",
// title: "All countries",
// json: { "type": "dropdown", optionsCaption: "Select a country...", choicesByUrl: { url: "https://surveyjs.io/api/CountriesExample" } }
// });
ref.current.render("surveyCreatorContainer");
console.log(ref.current)
}, [])
let saveSurvey = () => {
if (save)
save(JSON.stringify(ref.current.JSON));
console.log(ref.current)
}
return (
<>
<div id="surveyCreatorContainer" />
<div className="row">
<div className="form-group col-12">
<button onClick={() => saveSurvey()} className="btn btn-primary">
Valider
</button>
</div>
</div>
</>
)
}
ST
3 years ago
Hello,
If the example shared by Andrew - https://plnkr.co/edit/7NzaHut3kqS7xwg6?preview - worked for you, you could modify it to illustrate the issue.
Thanks, Serge
SurveyJS Team