Skip to content

Commit

Permalink
display questionnaire in the current locale
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Jan 23, 2025
1 parent 202a319 commit 6aaf184
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export default {
if (!this.userLoggedIn()) {
const response = await this.getAnonymousUserResponse();
this.userResponse = response.data.questionnaire_response ?? null;
console.log(this.userResponse);
this.displayLoginPrompt = !this.userResponse;
}
this.initQuestionnaireDisplay();
Expand Down Expand Up @@ -217,7 +216,10 @@ export default {
this.survey.onValueChanged.add(this.saveQuestionnaireResponseProgress);
this.survey.onComplete.add(this.saveQuestionnaireResponse);
this.survey.onUploadFiles.add(this.onUploadSurveyFile);
if (this.surveyLocales && this.surveyLocales.length) {
// if the current locale exists in the survey locales, set it as the default locale
if (this.surveyLocales.find((l) => l.code === this.locale)) {
this.survey.locale = this.locale;
} else if (this.surveyLocales && this.surveyLocales.length) {
this.survey.locale = this.surveyLocales[0].code;
}
this.survey.onAfterRenderSurvey.add(() => {
Expand Down Expand Up @@ -398,23 +400,21 @@ export default {
return window.route("login", this.locale) + `?redirectTo=${window.location.href}`;
},
getDefaultLocaleForQuestionnaire() {
const locales = this.survey.getUsedLocales();
const url = window.location.href;
const start = this.getPosition(url, "/", 3) + 1;
const end = this.getPosition(url, "/", 4);
const urlLang = url.substring(start, end);
if (locales.indexOf(urlLang) !== -1) {
return urlLang;
let locale = this.locale;
// fix for the greek language (el to gr)
if (locale === "el") {
locale = "gr";
}
// fix for the greek language (gr to el)
if (urlLang === "gr") {
return "el";
const locales = this.survey.getUsedLocales();
// if the current locale exists in the survey locales, set it as the default locale
if (locales && locales.length && locales.includes(locale)) {
this.defaultLangCode = locale;
} else if (locales && locales.length) {
this.defaultLangCode = locales[0];
}
return this.defaultLangCode;
},
getPosition(str, subString, occurrence) {
return str.split(subString, occurrence).join(subString).length;
},
trans(key) {
return window.trans(key);
},
Expand Down

0 comments on commit 6aaf184

Please sign in to comment.