From 94c1998f4864897bbe9b9f43da81536d2159f89a Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Tue, 19 Nov 2024 21:23:23 +0200 Subject: [PATCH 1/3] Add getSurveyString function --- packages/survey-core/entries/chunks/model.ts | 2 +- packages/survey-core/src/actions/action.ts | 4 +-- .../src/actions/adaptive-container.ts | 4 +-- packages/survey-core/src/base.ts | 4 +-- packages/survey-core/src/dxSurveyService.ts | 4 +-- packages/survey-core/src/error.ts | 10 ++---- packages/survey-core/src/jsonobject.ts | 4 +-- packages/survey-core/src/localizablestring.ts | 4 +-- .../survey-core/src/question_baseselect.ts | 4 +-- packages/survey-core/src/question_boolean.ts | 1 - packages/survey-core/src/question_checkbox.ts | 1 - packages/survey-core/src/question_matrix.ts | 6 ++-- .../survey-core/src/question_radiogroup.ts | 1 - packages/survey-core/src/question_rating.ts | 6 ++-- packages/survey-core/src/questionfactory.ts | 15 ++++---- packages/survey-core/src/survey-error.ts | 4 +-- packages/survey-core/src/surveyStrings.ts | 5 ++- packages/survey-core/src/utils/utils.ts | 9 ++--- packages/survey-core/src/validator.ts | 1 - .../survey-core/tests/questionFileTests.ts | 34 +++++++++---------- tests/ko/survey_kotests.ts | 4 +-- 21 files changed, 60 insertions(+), 67 deletions(-) diff --git a/packages/survey-core/entries/chunks/model.ts b/packages/survey-core/entries/chunks/model.ts index 904d8c9a87..316611f154 100644 --- a/packages/survey-core/entries/chunks/model.ts +++ b/packages/survey-core/entries/chunks/model.ts @@ -243,7 +243,7 @@ export { Cover, CoverCell } from "../../src/header"; export { dxSurveyService } from "../../src/dxSurveyService"; export { englishStrings } from "../../src/localization/english"; -export { surveyLocalization, surveyStrings } from "../../src/surveyStrings"; +export { surveyLocalization, surveyStrings, getSurveyString } from "../../src/surveyStrings"; // export { cultureInfo } from "../../src/cultureInfo"; export { QuestionCustomWidget, diff --git a/packages/survey-core/src/actions/action.ts b/packages/survey-core/src/actions/action.ts index 6a7d1d7d96..ea05c19f09 100644 --- a/packages/survey-core/src/actions/action.ts +++ b/packages/survey-core/src/actions/action.ts @@ -1,6 +1,6 @@ import { ILocalizableOwner, LocalizableString } from "../localizablestring"; import { Base, ComputedUpdater } from "../base"; -import { surveyLocalization } from "../surveyStrings"; +import { getSurveyString } from "../surveyStrings"; import { property } from "../jsonobject"; import { IListModel, ListModel } from "../list"; import { IPopupOptionsBase, PopupModel } from "../popup"; @@ -540,7 +540,7 @@ export class Action extends BaseAction implements IAction, ILocalizableOwner { } private locTooltipChanged(): void { if (!this.locTooltipName) return; - this.tooltip = surveyLocalization.getString(this.locTooltipName, this.locTitle.locale); + this.tooltip = getSurveyString(this.locTooltipName, this.locTitle.locale); } //ILocalizableOwner diff --git a/packages/survey-core/src/actions/adaptive-container.ts b/packages/survey-core/src/actions/adaptive-container.ts index dfce6891a0..5456caf227 100644 --- a/packages/survey-core/src/actions/adaptive-container.ts +++ b/packages/survey-core/src/actions/adaptive-container.ts @@ -2,7 +2,7 @@ import { ResponsivityManager } from "../utils/responsivity-manager"; import { ListModel } from "../list"; import { Action, actionModeType, createDropdownActionModelAdvanced, IAction } from "./action"; import { ActionContainer } from "./container"; -import { surveyLocalization } from "../surveyStrings"; +import { getSurveyString } from "../surveyStrings"; export class AdaptiveActionContainer extends ActionContainer { public dotsItem: Action; @@ -76,7 +76,7 @@ export class AdaptiveActionContainer extends ActionCo innerCss: "sv-dots__item", iconName: "icon-more", visible: false, - tooltip: surveyLocalization.getString("more"), + tooltip: getSurveyString("more"), }, { items: [], allowSelection: false diff --git a/packages/survey-core/src/base.ts b/packages/survey-core/src/base.ts index 96732978e3..4c5f0e60f2 100644 --- a/packages/survey-core/src/base.ts +++ b/packages/survey-core/src/base.ts @@ -11,7 +11,7 @@ import { settings } from "./settings"; import { ItemValue } from "./itemvalue"; import { IElement, IFindElement, IProgressInfo, ISurvey, ILoadFromJSONOptions, ISaveToJSONOptions } from "./base-interfaces"; import { ExpressionRunner } from "./conditions"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { ConsoleWarnings } from "./console-warnings"; interface IExpressionRunnerInfo { @@ -830,7 +830,7 @@ export class Base { return !!locOwner ? locOwner.getLocale(): ""; } public getLocalizationString(strName: string): string { - return surveyLocalization.getString(strName, this.getLocale()); + return getSurveyString(strName, this.getLocale()); } public getLocalizationFormatString(strName: string, ...args: any[]): string { const str: any = this.getLocalizationString(strName); diff --git a/packages/survey-core/src/dxSurveyService.ts b/packages/survey-core/src/dxSurveyService.ts index e133a48bf5..6b56ccf1a5 100644 --- a/packages/survey-core/src/dxSurveyService.ts +++ b/packages/survey-core/src/dxSurveyService.ts @@ -1,5 +1,5 @@ import { settings } from "./settings"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; const surveyIOSite = "surveyjs.io"; const surveyIOMaxPostSize = 65536; @@ -60,7 +60,7 @@ export class dxSurveyService { onSendResult: (success: boolean, response: any, request?: any) => void, clientId: string = null, isPartialCompleted: boolean = false): void { if(!this.canSendResult(result)) { - onSendResult(false, surveyLocalization.getString("savingExceedSize", this.locale), undefined); + onSendResult(false, getSurveyString("savingExceedSize", this.locale), undefined); } else { this.sendResultCore(postId, result, onSendResult, clientId, isPartialCompleted); } diff --git a/packages/survey-core/src/error.ts b/packages/survey-core/src/error.ts index c9906f8af8..ac8cf1128c 100644 --- a/packages/survey-core/src/error.ts +++ b/packages/survey-core/src/error.ts @@ -1,4 +1,4 @@ -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { SurveyError } from "./survey-error"; import { ISurveyErrorOwner } from "./base-interfaces"; @@ -53,9 +53,7 @@ export class ExceedSizeError extends SurveyError { return "exceedsize"; } public getDefaultText(): string { - return surveyLocalization - .getString("exceedMaxSize") - ["format"](this.getTextSize()); + return getSurveyString("exceedMaxSize")["format"](this.getTextSize()); } private getTextSize() { var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; @@ -150,9 +148,7 @@ export class MinRowCountError extends SurveyError { return "minrowcounterror"; } protected getDefaultText(): string { - return surveyLocalization - .getString("minRowCountError") - ["format"](this.minRowCount); + return getSurveyString("minRowCountError")["format"](this.minRowCount); } } export class KeyDuplicationError extends SurveyError { diff --git a/packages/survey-core/src/jsonobject.ts b/packages/survey-core/src/jsonobject.ts index 9140aca8f8..bbdeab28f6 100644 --- a/packages/survey-core/src/jsonobject.ts +++ b/packages/survey-core/src/jsonobject.ts @@ -1,4 +1,4 @@ -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { Base, ComputedUpdater } from "./base"; import { Helpers, HashTable } from "./helpers"; import { ILoadFromJSONOptions, ISaveToJSONOptions } from "./base-interfaces"; @@ -43,7 +43,7 @@ function getLocStringValue( if (!!res) return res; if (typeof options.localizable === "object" && options.localizable.defaultStr) { const loc = !!target.getLocale ? target.getLocale() : ""; - return surveyLocalization.getString(options.localizable.defaultStr, loc); + return getSurveyString(options.localizable.defaultStr, loc); } return ""; } diff --git a/packages/survey-core/src/localizablestring.ts b/packages/survey-core/src/localizablestring.ts index 0588c58b5b..3d377ffa7c 100644 --- a/packages/survey-core/src/localizablestring.ts +++ b/packages/survey-core/src/localizablestring.ts @@ -1,5 +1,5 @@ import { Helpers } from "./helpers"; -import { surveyLocalization } from "./surveyStrings"; +import { surveyLocalization, getSurveyString } from "./surveyStrings"; import { settings } from "./settings"; import { Base, EventBase } from "./base"; import { Serializer } from "./jsonobject"; @@ -156,7 +156,7 @@ export class LocalizableString implements ILocalizableString { } private getLocalizationStr(): string { const name = this.getLocalizationName(); - return !!name ? surveyLocalization.getString(name, this.locale) : ""; + return !!name ? getSurveyString(name, this.locale) : ""; } public get hasHtml(): boolean { return this.hasHtmlValue(); diff --git a/packages/survey-core/src/question_baseselect.ts b/packages/survey-core/src/question_baseselect.ts index f0c801ceb7..9c75a7d7fd 100644 --- a/packages/survey-core/src/question_baseselect.ts +++ b/packages/survey-core/src/question_baseselect.ts @@ -4,7 +4,7 @@ import { ISurveyImpl, ISurvey, ISurveyData, IPlainDataOptions, IValueItemCustomP import { SurveyModel } from "./survey"; import { IQuestionPlainData, Question } from "./question"; import { ItemValue } from "./itemvalue"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { OtherEmptyError } from "./error"; import { ChoicesRestful } from "./choicesRestful"; import { LocalizableString } from "./localizablestring"; @@ -2119,7 +2119,7 @@ Serializer.addClass( { name: "choices:itemvalue[]", uniqueProperty: "value", baseValue: function () { - return surveyLocalization.getString("choices_Item"); + return getSurveyString("choices_Item"); }, dependsOn: "choicesFromQuestion", visibleIf: (obj: any) => { diff --git a/packages/survey-core/src/question_boolean.ts b/packages/survey-core/src/question_boolean.ts index 475bbe8cb6..dc72234a29 100644 --- a/packages/survey-core/src/question_boolean.ts +++ b/packages/survey-core/src/question_boolean.ts @@ -2,7 +2,6 @@ import { QuestionFactory } from "./questionfactory"; import { property, Serializer } from "./jsonobject"; import { Question } from "./question"; import { LocalizableString } from "./localizablestring"; -import { surveyLocalization } from "./surveyStrings"; import { CssClassBuilder } from "./utils/cssClassBuilder"; import { preventDefaults } from "./utils/utils"; import { ActionContainer } from "./actions/container"; diff --git a/packages/survey-core/src/question_checkbox.ts b/packages/survey-core/src/question_checkbox.ts index 220bdc1373..e2384e7b9c 100644 --- a/packages/survey-core/src/question_checkbox.ts +++ b/packages/survey-core/src/question_checkbox.ts @@ -6,7 +6,6 @@ import { } from "./question_baseselect"; import { Helpers } from "./helpers"; import { ItemValue } from "./itemvalue"; -import { surveyLocalization } from "./surveyStrings"; import { LocalizableString } from "./localizablestring"; import { CssClassBuilder } from "./utils/cssClassBuilder"; import { IQuestion } from "./base-interfaces"; diff --git a/packages/survey-core/src/question_matrix.ts b/packages/survey-core/src/question_matrix.ts index 72e5058830..e74d31d0a2 100644 --- a/packages/survey-core/src/question_matrix.ts +++ b/packages/survey-core/src/question_matrix.ts @@ -4,7 +4,7 @@ import { QuestionMatrixBaseModel } from "./martixBase"; import { JsonObject, Serializer } from "./jsonobject"; import { Base } from "./base"; import { SurveyError } from "./survey-error"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { RequiredInAllRowsError, EachRowUniqueError } from "./error"; import { QuestionFactory } from "./questionfactory"; import { LocalizableString, ILocalizableOwner } from "./localizablestring"; @@ -794,13 +794,13 @@ Serializer.addClass( { name: "columns:itemvalue[]", uniqueProperty: "value", baseValue: function() { - return surveyLocalization.getString("matrix_column"); + return getSurveyString("matrix_column"); }, }, { name: "rows:itemvalue[]", uniqueProperty: "value", baseValue: function() { - return surveyLocalization.getString("matrix_row"); + return getSurveyString("matrix_row"); }, }, { name: "cells:cells", serializationProperty: "cells" }, diff --git a/packages/survey-core/src/question_radiogroup.ts b/packages/survey-core/src/question_radiogroup.ts index 97609fbfc9..67c97fe795 100644 --- a/packages/survey-core/src/question_radiogroup.ts +++ b/packages/survey-core/src/question_radiogroup.ts @@ -1,7 +1,6 @@ import { Serializer } from "./jsonobject"; import { QuestionFactory } from "./questionfactory"; import { QuestionCheckboxBase } from "./question_baseselect"; -import { surveyLocalization } from "./surveyStrings"; import { ItemValue } from "./itemvalue"; import { Action } from "./actions/action"; import { ComputedUpdater } from "./base"; diff --git a/packages/survey-core/src/question_rating.ts b/packages/survey-core/src/question_rating.ts index 40d7545b18..0656e1c1ad 100644 --- a/packages/survey-core/src/question_rating.ts +++ b/packages/survey-core/src/question_rating.ts @@ -4,7 +4,7 @@ import { property, propertyArray, Serializer } from "./jsonobject"; import { QuestionFactory } from "./questionfactory"; import { LocalizableString } from "./localizablestring"; import { settings } from "./settings"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { CssClassBuilder } from "./utils/cssClassBuilder"; import { Base } from "./base"; import { mergeValues } from "./utils/utils"; @@ -169,7 +169,7 @@ export class QuestionRatingModel extends Question { this.rateValues.splice(this.rateCount, this.rateValues.length - this.rateCount); } else { for (let i = this.rateValues.length; i < this.rateCount; i++) { - this.rateValues.push(new ItemValue(surveyLocalization.getString("choices_Item") + (i + 1))); + this.rateValues.push(new ItemValue(getSurveyString("choices_Item") + (i + 1))); } } } @@ -982,7 +982,7 @@ Serializer.addClass( { name: "rateValues:itemvalue[]", baseValue: function () { - return surveyLocalization.getString("choices_Item"); + return getSurveyString("choices_Item"); }, category: "rateValues", visibleIf: function (obj: any) { diff --git a/packages/survey-core/src/questionfactory.ts b/packages/survey-core/src/questionfactory.ts index 393f395e99..fdd495a712 100644 --- a/packages/survey-core/src/questionfactory.ts +++ b/packages/survey-core/src/questionfactory.ts @@ -1,29 +1,26 @@ import { HashTable } from "./helpers"; import { Question } from "./question"; import { IElement } from "./base-interfaces"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; import { Serializer } from "./jsonobject"; import { ComponentCollection } from "./question_custom"; export class QuestionFactory { public static Instance: QuestionFactory = new QuestionFactory(); public static get DefaultChoices(): string[] { - return [ - surveyLocalization.getString("choices_Item") + "1", - surveyLocalization.getString("choices_Item") + "2", - surveyLocalization.getString("choices_Item") + "3", - ]; + const choice = getSurveyString("choices_Item"); + return [choice + "1", choice + "2", choice + "3"]; } public static get DefaultColums(): string[] { - var colName = surveyLocalization.getString("matrix_column") + " "; + var colName = getSurveyString("matrix_column") + " "; return [colName + "1", colName + "2", colName + "3"]; } public static get DefaultRows(): string[] { - var rowName = surveyLocalization.getString("matrix_row") + " "; + var rowName = getSurveyString("matrix_row") + " "; return [rowName + "1", rowName + "2"]; } public static get DefaultMutlipleTextItems(): string[] { - var itemName = surveyLocalization.getString("multipletext_itemname"); + var itemName = getSurveyString("multipletext_itemname"); return [itemName + "1", itemName + "2"]; } public registerQuestion(questionType: string, questionCreator: (name: string) => Question, showInToolbox: boolean = true): void { diff --git a/packages/survey-core/src/survey-error.ts b/packages/survey-core/src/survey-error.ts index 61aaf0d4f0..eddb624615 100644 --- a/packages/survey-core/src/survey-error.ts +++ b/packages/survey-core/src/survey-error.ts @@ -1,6 +1,6 @@ import { ISurveyErrorOwner } from "./base-interfaces"; import { LocalizableString } from "./localizablestring"; -import { surveyLocalization } from "./surveyStrings"; +import { getSurveyString } from "./surveyStrings"; export class SurveyError { private locTextValue: LocalizableString; @@ -41,7 +41,7 @@ export class SurveyError { return !!this.errorOwner ? this.errorOwner.getLocale(): ""; } protected getLocalizationString(locStrName: string): string { - return surveyLocalization.getString(locStrName, this.getLocale()); + return getSurveyString(locStrName, this.getLocale()); } public onUpdateErrorTextCallback: (error: SurveyError) => void = undefined; public updateText(): void { diff --git a/packages/survey-core/src/surveyStrings.ts b/packages/survey-core/src/surveyStrings.ts index 4ddee226a3..2d933cd478 100644 --- a/packages/survey-core/src/surveyStrings.ts +++ b/packages/survey-core/src/surveyStrings.ts @@ -37,7 +37,7 @@ export var surveyLocalization = { getLocaleStrings(loc: string): any { return this.locales[loc]; }, - getString: function (strName: string, locale: string = null) { + getString: function (strName: string, locale: string = null): string { const locs = new Array(); const addLocaleCore = (locName: string): void => { const strs = this.locales[locName]; @@ -98,6 +98,9 @@ export var surveyLocalization = { onGetExternalString: function (name: string, locale: string): string { return undefined; } }; +export function getSurveyString(strName: string, locale: string = null): string { + return surveyLocalization.getString(strName, locale); +} export var surveyStrings = englishStrings; (surveyLocalization).locales["en"] = englishStrings; (surveyLocalization).localeNames["en"] = "english"; diff --git a/packages/survey-core/src/utils/utils.ts b/packages/survey-core/src/utils/utils.ts index f5d7f293a2..57f8fb75ce 100644 --- a/packages/survey-core/src/utils/utils.ts +++ b/packages/survey-core/src/utils/utils.ts @@ -1,10 +1,11 @@ import { LocalizableString } from "../localizablestring"; import { settings, ISurveyEnvironment } from "./../settings"; import { IDialogOptions } from "../popup"; -import { surveyLocalization } from "../surveyStrings"; +import { getSurveyString } from "../surveyStrings"; import { PopupBaseViewModel } from "../popup-view-model"; import { DomDocumentHelper, DomWindowHelper } from "../global_variables_utils"; -function compareVersions(a: any, b: any) { + +function compareVersions(a: any, b: any): number { const regExStrip0: RegExp = /(\.0+)+$/; const segmentsA: string[] = a.replace(regExStrip0, "").split("."); const segmentsB: string[] = b.replace(regExStrip0, "").split("."); @@ -617,9 +618,9 @@ export function showConfirmDialog(message: string, callback: (res: boolean) => v const toolbar = popupViewModel.footerToolbar; const applyBtn = toolbar.getActionById("apply"); const cancelBtn = toolbar.getActionById("cancel"); - cancelBtn.title = surveyLocalization.getString("cancel", locale); + cancelBtn.title = getSurveyString("cancel", locale); cancelBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sd-btn sd-btn--small"; - applyBtn.title = applyTitle || surveyLocalization.getString("ok", locale); + applyBtn.title = applyTitle || getSurveyString("ok", locale); applyBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sv-popup__button--danger sd-btn sd-btn--small sd-btn--danger"; configConfirmDialog(popupViewModel); return true; diff --git a/packages/survey-core/src/validator.ts b/packages/survey-core/src/validator.ts index f14f51020f..2eae4e62a0 100644 --- a/packages/survey-core/src/validator.ts +++ b/packages/survey-core/src/validator.ts @@ -2,7 +2,6 @@ import { Base } from "./base"; import { ISurveyErrorOwner, ISurvey } from "./base-interfaces"; import { SurveyError } from "./survey-error"; import { CustomError, RequreNumericError } from "./error"; -import { surveyLocalization } from "./surveyStrings"; import { ILocalizableOwner, LocalizableString } from "./localizablestring"; import { Serializer } from "./jsonobject"; import { ConditionRunner } from "./conditions"; diff --git a/packages/survey-core/tests/questionFileTests.ts b/packages/survey-core/tests/questionFileTests.ts index 571752163c..2fa0921556 100644 --- a/packages/survey-core/tests/questionFileTests.ts +++ b/packages/survey-core/tests/questionFileTests.ts @@ -1,7 +1,7 @@ import { SurveyModel } from "../src/survey"; import { QuestionFileModel } from "../src/question_file"; import { QuestionPanelDynamicModel } from "../src/question_paneldynamic"; -import { surveyLocalization } from "../src/surveyStrings"; +import { getSurveyString } from "../src/surveyStrings"; import { settings } from "../src/settings"; import { StylesManager } from "@legacy/stylesmanager"; import { Serializer } from "../src/jsonobject"; @@ -605,51 +605,51 @@ QUnit.test("Writable captions", function (assert) { /** * The remove file confirmation message template. */ - assert.equal(q.confirmRemoveMessage, surveyLocalization.getString("confirmRemoveFile"), "The remove file confirmation message template default"); + assert.equal(q.confirmRemoveMessage, getSurveyString("confirmRemoveFile"), "The remove file confirmation message template default"); q.confirmRemoveMessage += "_new"; - assert.equal(q.confirmRemoveMessage, surveyLocalization.getString("confirmRemoveFile") + "_new", "The remove file confirmation message template new"); + assert.equal(q.confirmRemoveMessage, getSurveyString("confirmRemoveFile") + "_new", "The remove file confirmation message template new"); /** * The remove all files confirmation message. */ - assert.equal(q.confirmRemoveAllMessage, surveyLocalization.getString("confirmRemoveAllFiles"), "The remove all files confirmation message default"); + assert.equal(q.confirmRemoveAllMessage, getSurveyString("confirmRemoveAllFiles"), "The remove all files confirmation message default"); q.confirmRemoveAllMessage += "_new"; - assert.equal(q.confirmRemoveAllMessage, surveyLocalization.getString("confirmRemoveAllFiles") + "_new", "The remove all files confirmation message new"); + assert.equal(q.confirmRemoveAllMessage, getSurveyString("confirmRemoveAllFiles") + "_new", "The remove all files confirmation message new"); /** * The no file chosen caption for modern theme. */ - assert.equal(q.noFileChosenCaption, surveyLocalization.getString("noFileChosen"), "The no file chosen caption for modern theme default"); + assert.equal(q.noFileChosenCaption, getSurveyString("noFileChosen"), "The no file chosen caption for modern theme default"); q.noFileChosenCaption += "_new"; - assert.equal(q.noFileChosenCaption, surveyLocalization.getString("noFileChosen") + "_new", "The no file chosen caption for modern theme new"); + assert.equal(q.noFileChosenCaption, getSurveyString("noFileChosen") + "_new", "The no file chosen caption for modern theme new"); /** * The choose files button caption for modern theme. */ - assert.equal(q.chooseButtonCaption, surveyLocalization.getString("chooseFileCaption"), "The choose files button caption for modern theme default"); + assert.equal(q.chooseButtonCaption, getSurveyString("chooseFileCaption"), "The choose files button caption for modern theme default"); q.chooseButtonCaption += "_new"; - assert.equal(q.chooseButtonCaption, surveyLocalization.getString("chooseFileCaption") + "_new", "The choose files button caption for modern theme new"); + assert.equal(q.chooseButtonCaption, getSurveyString("chooseFileCaption") + "_new", "The choose files button caption for modern theme new"); /** * The clean files button caption. */ - assert.equal(q.clearButtonCaption, surveyLocalization.getString("clearCaption"), "The clean files button caption default"); + assert.equal(q.clearButtonCaption, getSurveyString("clearCaption"), "The clean files button caption default"); q.clearButtonCaption += "_new"; - assert.equal(q.clearButtonCaption, surveyLocalization.getString("clearCaption") + "_new", "The clean files button caption new"); + assert.equal(q.clearButtonCaption, getSurveyString("clearCaption") + "_new", "The clean files button caption new"); /** * The remove file button caption. */ - assert.equal(q.removeFileCaption, surveyLocalization.getString("removeFileCaption"), "The remove file button caption default"); + assert.equal(q.removeFileCaption, getSurveyString("removeFileCaption"), "The remove file button caption default"); q.removeFileCaption += "_new"; - assert.equal(q.removeFileCaption, surveyLocalization.getString("removeFileCaption") + "_new", "The remove file button caption new"); + assert.equal(q.removeFileCaption, getSurveyString("removeFileCaption") + "_new", "The remove file button caption new"); /** * The loading file input title. */ - assert.equal(q.loadingFileTitle, surveyLocalization.getString("loadingFile"), "The loading file input title default"); + assert.equal(q.loadingFileTitle, getSurveyString("loadingFile"), "The loading file input title default"); q.loadingFileTitle += "_new"; - assert.equal(q.loadingFileTitle, surveyLocalization.getString("loadingFile") + "_new", "The loading file input title new"); + assert.equal(q.loadingFileTitle, getSurveyString("loadingFile") + "_new", "The loading file input title new"); /** * The choose file input title. */ - assert.equal(q.chooseFileTitle, surveyLocalization.getString("chooseFile"), "The choose file input title default"); + assert.equal(q.chooseFileTitle, getSurveyString("chooseFile"), "The choose file input title default"); q.chooseFileTitle += "_new"; - assert.equal(q.chooseFileTitle, surveyLocalization.getString("chooseFile") + "_new", "The choose file input title new"); + assert.equal(q.chooseFileTitle, getSurveyString("chooseFile") + "_new", "The choose file input title new"); }); diff --git a/tests/ko/survey_kotests.ts b/tests/ko/survey_kotests.ts index 75fdd97ee8..0610e6fada 100644 --- a/tests/ko/survey_kotests.ts +++ b/tests/ko/survey_kotests.ts @@ -13,7 +13,7 @@ import { Page, Panel, QuestionRow } from "../../src/knockout/kopage"; import { CustomWidgetCollection } from "../../packages/survey-core/src//questionCustomWidgets"; import { koTemplate } from "../../src/knockout/templateText"; import { QuestionMatrixDynamic } from "../../src/knockout/koquestion_matrixdynamic"; -import { surveyLocalization } from "../../packages/survey-core/src//surveyStrings"; +import { getSurveyString } from "../../packages/survey-core/src//surveyStrings"; import { QuestionRating } from "../../src/knockout/koquestion_rating"; import { QuestionImagePicker } from "../../src/knockout/koquestion_imagepicker"; import { ImageItemValue } from "../../packages/survey-core/src//question_imagepicker"; @@ -441,7 +441,7 @@ QUnit.test("Localization, otherItem", function (assert) { var defaultText = q1.visibleChoices[2].locText["koRenderedHtml"](); assert.equal( q1.visibleChoices[2].locText["koRenderedHtml"](), - surveyLocalization.getString("otherItemText"), + getSurveyString("otherItemText"), "use default locale" ); survey.locale = "de"; From ff74798d2899d7e0e146c4f8fa499b0ea753f94e Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Tue, 19 Nov 2024 21:42:51 +0200 Subject: [PATCH 2/3] Fix compile errors --- packages/survey-core/src/error.ts | 4 ++-- packages/survey-core/src/surveyStrings.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/survey-core/src/error.ts b/packages/survey-core/src/error.ts index ac8cf1128c..0d572d2c97 100644 --- a/packages/survey-core/src/error.ts +++ b/packages/survey-core/src/error.ts @@ -53,7 +53,7 @@ export class ExceedSizeError extends SurveyError { return "exceedsize"; } public getDefaultText(): string { - return getSurveyString("exceedMaxSize")["format"](this.getTextSize()); + return (getSurveyString("exceedMaxSize"))["format"](this.getTextSize()); } private getTextSize() { var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; @@ -148,7 +148,7 @@ export class MinRowCountError extends SurveyError { return "minrowcounterror"; } protected getDefaultText(): string { - return getSurveyString("minRowCountError")["format"](this.minRowCount); + return (getSurveyString("minRowCountError"))["format"](this.minRowCount); } } export class KeyDuplicationError extends SurveyError { diff --git a/packages/survey-core/src/surveyStrings.ts b/packages/survey-core/src/surveyStrings.ts index 2d933cd478..d2b28108b3 100644 --- a/packages/survey-core/src/surveyStrings.ts +++ b/packages/survey-core/src/surveyStrings.ts @@ -37,7 +37,7 @@ export var surveyLocalization = { getLocaleStrings(loc: string): any { return this.locales[loc]; }, - getString: function (strName: string, locale: string = null): string { + getString: function (strName: string, locale: string = null) { const locs = new Array(); const addLocaleCore = (locName: string): void => { const strs = this.locales[locName]; From e77d0e3e024ea27c0ce22285498196664e840d8e Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Wed, 20 Nov 2024 10:17:52 +0200 Subject: [PATCH 3/3] Change getSurveyString to getLocaleString --- packages/survey-core/entries/chunks/model.ts | 2 +- packages/survey-core/src/actions/action.ts | 6 +- .../src/actions/adaptive-container.ts | 8 +- packages/survey-core/src/base.ts | 82 ++++---- packages/survey-core/src/dxSurveyService.ts | 16 +- packages/survey-core/src/error.ts | 6 +- packages/survey-core/src/jsonobject.ts | 190 +++++++++--------- packages/survey-core/src/localizablestring.ts | 14 +- .../survey-core/src/question_baseselect.ts | 4 +- packages/survey-core/src/question_matrix.ts | 54 ++--- packages/survey-core/src/question_rating.ts | 6 +- packages/survey-core/src/questionfactory.ts | 10 +- packages/survey-core/src/survey-error.ts | 14 +- packages/survey-core/src/surveyStrings.ts | 20 +- packages/survey-core/src/utils/utils.ts | 42 ++-- .../survey-core/tests/questionFileTests.ts | 34 ++-- tests/ko/survey_kotests.ts | 4 +- 17 files changed, 257 insertions(+), 255 deletions(-) diff --git a/packages/survey-core/entries/chunks/model.ts b/packages/survey-core/entries/chunks/model.ts index 316611f154..3b9be16b9d 100644 --- a/packages/survey-core/entries/chunks/model.ts +++ b/packages/survey-core/entries/chunks/model.ts @@ -243,7 +243,7 @@ export { Cover, CoverCell } from "../../src/header"; export { dxSurveyService } from "../../src/dxSurveyService"; export { englishStrings } from "../../src/localization/english"; -export { surveyLocalization, surveyStrings, getSurveyString } from "../../src/surveyStrings"; +export { surveyLocalization, surveyStrings, getLocaleString } from "../../src/surveyStrings"; // export { cultureInfo } from "../../src/cultureInfo"; export { QuestionCustomWidget, diff --git a/packages/survey-core/src/actions/action.ts b/packages/survey-core/src/actions/action.ts index ea05c19f09..7f81b1a208 100644 --- a/packages/survey-core/src/actions/action.ts +++ b/packages/survey-core/src/actions/action.ts @@ -1,6 +1,6 @@ import { ILocalizableOwner, LocalizableString } from "../localizablestring"; import { Base, ComputedUpdater } from "../base"; -import { getSurveyString } from "../surveyStrings"; +import { getLocaleString } from "../surveyStrings"; import { property } from "../jsonobject"; import { IListModel, ListModel } from "../list"; import { IPopupOptionsBase, PopupModel } from "../popup"; @@ -540,7 +540,7 @@ export class Action extends BaseAction implements IAction, ILocalizableOwner { } private locTooltipChanged(): void { if (!this.locTooltipName) return; - this.tooltip = getSurveyString(this.locTooltipName, this.locTitle.locale); + this.tooltip = getLocaleString(this.locTooltipName, this.locTitle.locale); } //ILocalizableOwner @@ -551,7 +551,7 @@ export class Action extends BaseAction implements IAction, ILocalizableOwner { getRendererContext(locStr: LocalizableString): any { return this.owner ? this.owner.getRendererContext(locStr) : locStr; } public setVisible(val: boolean): void { - if(this.visible !== val) { + if (this.visible !== val) { this._visible = val; } } diff --git a/packages/survey-core/src/actions/adaptive-container.ts b/packages/survey-core/src/actions/adaptive-container.ts index 5456caf227..376a86faee 100644 --- a/packages/survey-core/src/actions/adaptive-container.ts +++ b/packages/survey-core/src/actions/adaptive-container.ts @@ -2,7 +2,7 @@ import { ResponsivityManager } from "../utils/responsivity-manager"; import { ListModel } from "../list"; import { Action, actionModeType, createDropdownActionModelAdvanced, IAction } from "./action"; import { ActionContainer } from "./container"; -import { getSurveyString } from "../surveyStrings"; +import { getLocaleString } from "../surveyStrings"; export class AdaptiveActionContainer extends ActionContainer { public dotsItem: Action; @@ -16,7 +16,7 @@ export class AdaptiveActionContainer extends ActionCo const hiddenItems: IAction[] = []; actionsToHide.forEach((item) => { if (visibleItemsCount <= 0) { - if(item.removePriority) { + if (item.removePriority) { item.mode = "removed"; } else { item.mode = "popup"; @@ -76,7 +76,7 @@ export class AdaptiveActionContainer extends ActionCo innerCss: "sv-dots__item", iconName: "icon-more", visible: false, - tooltip: getSurveyString("more"), + tooltip: getLocaleString("more"), }, { items: [], allowSelection: false @@ -152,7 +152,7 @@ export class AdaptiveActionContainer extends ActionCo } public setActionsMode(mode: actionModeType) { this.actions.forEach((action) => { - if(mode == "small" && action.disableShrink) return; + if (mode == "small" && action.disableShrink) return; action.mode = mode; }); } diff --git a/packages/survey-core/src/base.ts b/packages/survey-core/src/base.ts index 4c5f0e60f2..20a018b6f5 100644 --- a/packages/survey-core/src/base.ts +++ b/packages/survey-core/src/base.ts @@ -11,7 +11,7 @@ import { settings } from "./settings"; import { ItemValue } from "./itemvalue"; import { IElement, IFindElement, IProgressInfo, ISurvey, ILoadFromJSONOptions, ISaveToJSONOptions } from "./base-interfaces"; import { ExpressionRunner } from "./conditions"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { ConsoleWarnings } from "./console-warnings"; interface IExpressionRunnerInfo { @@ -47,7 +47,7 @@ export class Bindings { public setBinding(propertyName: string, valueName: string) { if (!this.values) this.values = {}; const oldValue = this.getJson(); - if(oldValue === valueName) return; + if (oldValue === valueName) return; if (!!valueName) { this.values[propertyName] = valueName; } else { @@ -62,8 +62,8 @@ export class Bindings { this.setBinding(propertyName, ""); } public isEmpty(): boolean { - if(!this.values) return true; - for(var key in this.values) return false; + if (!this.values) return true; + for (var key in this.values) return false; return true; } public getValueNameByPropertyName(propertyName: string): string { @@ -97,7 +97,7 @@ export class Bindings { this.values[key] = value[key]; } } - if(!isLoading) { + if (!isLoading) { this.onChangedJSON(oldValue); } } @@ -112,7 +112,7 @@ export class Bindings { } } private onChangedJSON(oldValue: any): void { - if(this.obj) { + if (this.obj) { this.obj.onBindingChanged(oldValue, this.getJson()); } } @@ -194,7 +194,7 @@ export class Base { if (Base.currentDependencis === undefined) return; Base.currentDependencis.addDependency(target, property); } - public dependencies: {[key: string]: ComputedUpdater } = {}; + public dependencies: { [key: string]: ComputedUpdater } = {}; public static get commentSuffix(): string { return settings.commentSuffix; } @@ -222,13 +222,13 @@ export class Base { return Helpers.isValueEmpty(value); } public equals(obj: Base): boolean { - if(!obj) return false; + if (!obj) return false; if (this.isDisposed || obj.isDisposed) return false; - if(this.getType() != obj.getType()) return false; + if (this.getType() != obj.getType()) return false; return this.equalsCore(obj); } protected equalsCore(obj: Base): boolean { - if((this).name !== (obj).name) return false; + if ((this).name !== (obj).name) return false; return Helpers.isTwoValueEquals(this.toJSON(), obj.toJSON(), false, true, false); } protected trimValue(value: any): any { @@ -448,7 +448,7 @@ export class Base { */ public getPropertyByName(propName: string): JsonObjectProperty { const type = this.getType(); - if(!this.classMetaData || this.classMetaData.name !== type) { + if (!this.classMetaData || this.classMetaData.name !== type) { this.classMetaData = Serializer.findClass(type); } return !!this.classMetaData ? this.classMetaData.findProperty(propName) : null; @@ -499,21 +499,21 @@ export class Base { const res = this.getPropertyValueWithoutDefault(name); if (this.isPropertyEmpty(res)) { const locStr = this.localizableStrings ? this.localizableStrings[name] : undefined; - if(locStr) return locStr.text; + if (locStr) return locStr.text; if (defaultValue !== null && defaultValue !== undefined) return defaultValue; const propDefaultValue = this.getDefaultPropertyValue(name); - if(propDefaultValue !== undefined) return propDefaultValue; + if (propDefaultValue !== undefined) return propDefaultValue; } return res; } public getDefaultPropertyValue(name: string): any { const prop = this.getPropertyByName(name); - if(!prop || prop.isCustom && this.isCreating) return undefined; + if (!prop || prop.isCustom && this.isCreating) return undefined; const dValue = prop.defaultValue; if (!!prop.defaultValueFunc) return dValue; if (!this.isPropertyEmpty(dValue) && !Array.isArray(dValue)) return dValue; const locStr = this.localizableStrings ? this.localizableStrings[name] : undefined; - if(locStr && locStr.localizationName) return this.getLocalizationString(locStr.localizationName); + if (locStr && locStr.localizationName) return this.getLocalizationString(locStr.localizationName); if (prop.type == "boolean" || prop.type == "switch") return false; if (prop.isCustom && !!prop.onGetValue) return prop.onGetValue(this); return undefined; @@ -523,7 +523,7 @@ export class Base { } public resetPropertyValue(name: string): void { const locStr = this.localizableStrings ? this.localizableStrings[name] : undefined; - if(locStr) { + if (locStr) { this.setLocalizableStringText(name, undefined); locStr.clear(); } @@ -535,7 +535,7 @@ export class Base { return this.getPropertyValueCore(this.propertyHash, name); } protected getPropertyValueCore(propertiesHash: any, name: string): any { - if(!this.isLoadingFromJson) { + if (!this.isLoadingFromJson) { Base.collectDependency(this, name); } if (this.getPropertyValueCoreHandler) @@ -579,9 +579,9 @@ export class Base { * @param val A new value for the property. */ public setPropertyValue(name: string, val: any): void { - if(!this.isLoadingFromJson) { + if (!this.isLoadingFromJson) { const prop = this.getPropertyByName(name); - if(!!prop) { + if (!!prop) { val = prop.settingValue(this, val); } } @@ -612,7 +612,7 @@ export class Base { arrayInfo ? sendNotification && arrayInfo.onPush : null ); } - protected setPropertyValueDirectly(name: string, val: any) : void { + protected setPropertyValueDirectly(name: string, val: any): void { this.setPropertyValueCore(this.propertyHash, name, val); } protected clearPropertyValue(name: string) { @@ -667,7 +667,7 @@ export class Base { } } public onBindingChanged(oldValue: any, newValue: any): void { - if(this.isLoadingFromJson) return; + if (this.isLoadingFromJson) return; this.doPropertyValueChangedCallback("bindings", oldValue, newValue); } protected get isInternal(): boolean { @@ -698,7 +698,7 @@ export class Base { } } public addExpressionProperty(name: string, onExecute: (obj: Base, res: any) => void, canRun?: (obj: Base) => boolean): void { - if(!this.expressionInfo) { + if (!this.expressionInfo) { this.expressionInfo = {}; } this.expressionInfo[name] = { onExecute: onExecute, canRun: canRun }; @@ -710,8 +710,8 @@ export class Base { return {}; } protected runConditionCore(values: HashTable, properties: HashTable): void { - if(!this.expressionInfo) return; - for(var key in this.expressionInfo) { + if (!this.expressionInfo) return; + for (var key in this.expressionInfo) { this.runConditionItemCore(key, values, properties); } } @@ -719,16 +719,16 @@ export class Base { return !this.isDesignMode; } private checkConditionPropertyChanged(propName: string): void { - if(!this.expressionInfo || !this.expressionInfo[propName]) return; - if(!this.canRunConditions()) return; + if (!this.expressionInfo || !this.expressionInfo[propName]) return; + if (!this.canRunConditions()) return; this.runConditionItemCore(propName, this.getDataFilteredValues(), this.getDataFilteredProperties()); } private runConditionItemCore(propName: string, values: HashTable, properties: HashTable): void { const info = this.expressionInfo[propName]; const expression = this.getPropertyValue(propName); - if(!expression) return; - if(!!info.canRun && !info.canRun(this)) return; - if(!info.runner) { + if (!expression) return; + if (!!info.canRun && !info.canRun(this)) return; + if (!info.runner) { info.runner = this.createExpressionRunner(expression); info.runner.onRunComplete = (res: any) => { info.onExecute(this, res); @@ -739,22 +739,22 @@ export class Base { } private asynExpressionHash: any; private doBeforeAsynRun(id: number): void { - if(!this.asynExpressionHash) this.asynExpressionHash = {}; + if (!this.asynExpressionHash) this.asynExpressionHash = {}; const isChanged = !this.isAsyncExpressionRunning; this.asynExpressionHash[id] = true; - if(isChanged) { + if (isChanged) { this.onAsyncRunningChanged(); } } private doAfterAsynRun(id: number): void { - if(!!this.asynExpressionHash) { + if (!!this.asynExpressionHash) { delete this.asynExpressionHash[id]; - if(!this.isAsyncExpressionRunning) { + if (!this.isAsyncExpressionRunning) { this.onAsyncRunningChanged(); } } } - protected onAsyncRunningChanged(): void {} + protected onAsyncRunningChanged(): void { } public get isAsyncExpressionRunning(): boolean { return !!this.asynExpressionHash && Object.keys(this.asynExpressionHash).length > 0; } @@ -822,26 +822,26 @@ export class Base { } public createCustomLocalizableObj(name: string): LocalizableString { const locStr = this.getLocalizableString(name); - if(locStr) return locStr; + if (locStr) return locStr; return this.createLocalizableString(name, (this), false, true); } public getLocale(): string { const locOwner = this.getSurvey(); - return !!locOwner ? locOwner.getLocale(): ""; + return !!locOwner ? locOwner.getLocale() : ""; } public getLocalizationString(strName: string): string { - return getSurveyString(strName, this.getLocale()); + return getLocaleString(strName, this.getLocale()); } public getLocalizationFormatString(strName: string, ...args: any[]): string { const str: any = this.getLocalizationString(strName); - if(!str || !str.format) return ""; + if (!str || !str.format) return ""; return str.format(...args); } protected createLocalizableString( name: string, owner: ILocalizableOwner, useMarkDown: boolean = false, - defaultStr: boolean|string = false + defaultStr: boolean | string = false ): LocalizableString { let locName = undefined; if (defaultStr) { @@ -876,7 +876,7 @@ export class Base { let locStr = this.getLocalizableString(name); if (!locStr) return; let oldValue = locStr.text; - if(oldValue != value) { + if (oldValue != value) { locStr.text = value; // this.propertyValueChanged(name, oldValue, value); } @@ -891,7 +891,7 @@ export class Base { if (!!this.arraysInfo) { for (let key in this.arraysInfo) { const prop = this.getPropertyByName(key); - if(!prop || !prop.isSerializable) continue; + if (!prop || !prop.isSerializable) continue; let items = this.getPropertyValue(key); if (!items || !items.length) continue; for (let i = 0; i < items.length; i++) { diff --git a/packages/survey-core/src/dxSurveyService.ts b/packages/survey-core/src/dxSurveyService.ts index 6b56ccf1a5..44fec08a13 100644 --- a/packages/survey-core/src/dxSurveyService.ts +++ b/packages/survey-core/src/dxSurveyService.ts @@ -1,5 +1,5 @@ import { settings } from "./settings"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; const surveyIOSite = "surveyjs.io"; const surveyIOMaxPostSize = 65536; @@ -34,10 +34,10 @@ export class dxSurveyService { xhr.open( "GET", this.serviceUrl + - "/getSurveyAndIsCompleted?surveyId=" + - surveyId + - "&clientId=" + - clientId + "/getSurveyAndIsCompleted?surveyId=" + + surveyId + + "&clientId=" + + clientId ); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onload = function () { @@ -49,7 +49,7 @@ export class dxSurveyService { xhr.send(); } public canSendResult(result: JSON): boolean { - if(!this.isSurveJSIOService) return true; + if (!this.isSurveJSIOService) return true; const str = JSON.stringify(result); return str.length < surveyIOMaxPostSize; } @@ -59,8 +59,8 @@ export class dxSurveyService { public sendResult(postId: string, result: JSON, onSendResult: (success: boolean, response: any, request?: any) => void, clientId: string = null, isPartialCompleted: boolean = false): void { - if(!this.canSendResult(result)) { - onSendResult(false, getSurveyString("savingExceedSize", this.locale), undefined); + if (!this.canSendResult(result)) { + onSendResult(false, getLocaleString("savingExceedSize", this.locale), undefined); } else { this.sendResultCore(postId, result, onSendResult, clientId, isPartialCompleted); } diff --git a/packages/survey-core/src/error.ts b/packages/survey-core/src/error.ts index 0d572d2c97..dfead1b90b 100644 --- a/packages/survey-core/src/error.ts +++ b/packages/survey-core/src/error.ts @@ -1,4 +1,4 @@ -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { SurveyError } from "./survey-error"; import { ISurveyErrorOwner } from "./base-interfaces"; @@ -53,7 +53,7 @@ export class ExceedSizeError extends SurveyError { return "exceedsize"; } public getDefaultText(): string { - return (getSurveyString("exceedMaxSize"))["format"](this.getTextSize()); + return (getLocaleString("exceedMaxSize"))["format"](this.getTextSize()); } private getTextSize() { var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; @@ -148,7 +148,7 @@ export class MinRowCountError extends SurveyError { return "minrowcounterror"; } protected getDefaultText(): string { - return (getSurveyString("minRowCountError"))["format"](this.minRowCount); + return (getLocaleString("minRowCountError"))["format"](this.minRowCount); } } export class KeyDuplicationError extends SurveyError { diff --git a/packages/survey-core/src/jsonobject.ts b/packages/survey-core/src/jsonobject.ts index bbdeab28f6..f3bec76c7a 100644 --- a/packages/survey-core/src/jsonobject.ts +++ b/packages/survey-core/src/jsonobject.ts @@ -1,4 +1,4 @@ -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { Base, ComputedUpdater } from "./base"; import { Helpers, HashTable } from "./helpers"; import { ILoadFromJSONOptions, ISaveToJSONOptions } from "./base-interfaces"; @@ -21,7 +21,7 @@ function ensureLocString( let locString = target.getLocalizableString(key); if (!locString) { let defaultStr: string; - if(typeof options.localizable === "object" && options.localizable.defaultStr) { + if (typeof options.localizable === "object" && options.localizable.defaultStr) { defaultStr = options.localizable.defaultStr; } locString = target.createLocalizableString(key, target, true, defaultStr); @@ -43,7 +43,7 @@ function getLocStringValue( if (!!res) return res; if (typeof options.localizable === "object" && options.localizable.defaultStr) { const loc = !!target.getLocale ? target.getLocale() : ""; - return getSurveyString(options.localizable.defaultStr, loc); + return getLocaleString(options.localizable.defaultStr, loc); } return ""; } @@ -57,7 +57,7 @@ export function property(options: IPropertyDecoratorOptions = {}) { const result = val.updater(); const dependencies = Base.finishCollectDependencies(); val.setDependencies(dependencies); - if(obj.dependencies[key]) { + if (obj.dependencies[key]) { obj.dependencies[key].dispose(); } obj.dependencies[key] = val; @@ -365,9 +365,9 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { return this.isRequiredValue; } public set isRequired(val: boolean) { - if(val !== this.isRequired) { + if (val !== this.isRequired) { this.isRequiredValue = val; - if(!!this.classInfo) { + if (!!this.classInfo) { this.classInfo.resetAllProperties(); } } @@ -407,7 +407,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { return this.isDefaultValueByObj(undefined, value); } public isDefaultValueByObj(obj: Base, value: any): boolean { - if(this.isLocalizable) return value === null || value === undefined; + if (this.isLocalizable) return value === null || value === undefined; const dValue = this.getDefaultValue(obj); if (!Helpers.isValueEmpty(dValue)) { return Helpers.isTwoValueEquals(value, dValue, false, true, false); @@ -418,9 +418,9 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { ); } public getSerializableValue(obj: any, storeDefaults?: boolean): any { - if(!!this.onSerializeValue) return this.onSerializeValue(obj); + if (!!this.onSerializeValue) return this.onSerializeValue(obj); const value = this.getValue(obj); - if(value === undefined || value === null) return undefined; + if (value === undefined || value === null) return undefined; if (!storeDefaults && this.isDefaultValueByObj(obj, value)) return undefined; return value; } @@ -470,7 +470,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { } public validateValue(value: any): boolean { const choices = this.choices; - if(!Array.isArray(choices) || choices.length === 0) return true; + if (!Array.isArray(choices) || choices.length === 0) return true; return choices.indexOf(value) > -1; } public getObjType(objType: string) { @@ -513,8 +513,8 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { this.readOnlyValue = val; } public isEnable(obj: any): boolean { - if(this.readOnly) return false; - if(!obj || !this.enableIf) return true; + if (this.readOnly) return false; + if (!obj || !this.enableIf) return true; return this.enableIf(this.getOriginalObj(obj)); } public isVisible(layout: string, obj: any = null): boolean { @@ -528,7 +528,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { private getOriginalObj(obj: any): any { if (obj && obj.getOriginalObj) { const orjObj = obj.getOriginalObj(); - if(orjObj && Serializer.findProperty(orjObj.getType(), this.name)) { + if (orjObj && Serializer.findProperty(orjObj.getType(), this.name)) { return orjObj; } } @@ -541,20 +541,20 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { this.visibleValue = val; } public isAvailableInVersion(ver: string): boolean { - if(!!this.alternativeName || this.oldName) return true; + if (!!this.alternativeName || this.oldName) return true; return this.isAvailableInVersionCore(ver); } public getSerializedName(ver: string): string { - if(!this.alternativeName) return this.name; + if (!this.alternativeName) return this.name; return this.isAvailableInVersionCore(ver) ? this.name : this.alternativeName || this.oldName; } public getSerializedProperty(obj: any, ver: string): JsonObjectProperty { - if(!this.oldName || this.isAvailableInVersionCore(ver)) return this; - if(!obj || !obj.getType) return null; + if (!this.oldName || this.isAvailableInVersionCore(ver)) return this; + if (!obj || !obj.getType) return null; return Serializer.findProperty(obj.getType(), this.oldName); } private isAvailableInVersionCore(ver: string): boolean { - if(!ver || !this.version) return true; + if (!ver || !this.version) return true; return Helpers.compareVerions(this.version, ver) <= 0; } public get isLocalizable(): boolean { @@ -587,8 +587,8 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { return !!this.dependedProperties ? this.dependedProperties : []; } public schemaType(): string { - if(this.className === "choicesByUrl") return undefined; - if(this.className === "string") return this.className; + if (this.className === "choicesByUrl") return undefined; + if (this.className === "string") return this.className; if (!!this.className) return "array"; if (!!this.baseClassName) return "array"; if (this.type == "switch") return "boolean"; @@ -795,11 +795,11 @@ export class JsonMetadataClass { return this.allProperties; } public getRequiredProperties(): Array { - if(!!this.requiredProperties) return this.requiredProperties; + if (!!this.requiredProperties) return this.requiredProperties; this.requiredProperties = []; const props = this.getAllProperties(); - for(let i = 0; i < props.length; i ++) { - if(props[i].isRequired) this.requiredProperties.push(props[i]); + for (let i = 0; i < props.length; i++) { + if (props[i].isRequired) this.requiredProperties.push(props[i]); } return this.requiredProperties; } @@ -814,17 +814,17 @@ export class JsonMetadataClass { } public get isCustom(): boolean { return this.isCustomValue; } private fillAllProperties(): void { - if(!!this.allProperties) return; + if (!!this.allProperties) return; this.allProperties = []; this.hashProperties = {}; const localProperties: HashTable = {}; this.properties.forEach(prop => localProperties[prop.name] = prop); const parentClass = !!this.parentName ? Serializer.findClass(this.parentName) : null; - if(!!parentClass) { + if (!!parentClass) { const parentProperties = parentClass.getAllProperties(); parentProperties.forEach(prop => { const overridedProp = localProperties[prop.name]; - if(!!overridedProp) { + if (!!overridedProp) { overridedProp.mergeWith(prop); this.addPropCore(overridedProp); } else { @@ -833,7 +833,7 @@ export class JsonMetadataClass { }); } this.properties.forEach(prop => { - if(!this.hashProperties[prop.name]) { + if (!this.hashProperties[prop.name]) { this.addPropCore(prop); } }); @@ -841,7 +841,7 @@ export class JsonMetadataClass { private addPropCore(prop: JsonObjectProperty): void { this.allProperties.push(prop); this.hashProperties[prop.name] = prop; - if(!!prop.alternativeName) { + if (!!prop.alternativeName) { this.hashProperties[prop.alternativeName] = prop; } } @@ -962,7 +962,7 @@ export class JsonMetadataClass { if (propInfo.readOnly === true) { prop.readOnly = true; } - if(propInfo.availableInMatrixColumn === true) { + if (propInfo.availableInMatrixColumn === true) { prop.availableInMatrixColumn = true; } if (propInfo.choices) { @@ -1010,7 +1010,7 @@ export class JsonMetadataClass { prop.baseClassName = propInfo.baseClassName; prop.isArray = true; } - if(prop.isArray === true) { + if (prop.isArray === true) { prop.isArray = true; } if (propInfo.classNamePart) { @@ -1019,7 +1019,7 @@ export class JsonMetadataClass { if (propInfo.alternativeName) { prop.alternativeName = propInfo.alternativeName; } - if(propInfo.oldName) { + if (propInfo.oldName) { prop.oldName = propInfo.oldName; } if (propInfo.layout) { @@ -1112,11 +1112,11 @@ export class JsonMetadata { return !!obj.getOriginalObj && !!obj.getOriginalObj(); } private isNeedUseObjWrapper(obj: any, name: string): boolean { - if(!obj.getDynamicProperties) return true; + if (!obj.getDynamicProperties) return true; const props = obj.getDynamicProperties(); - if(!Array.isArray(props)) return false; - for(let i = 0; i < props.length; i ++) { - if(props[i].name === name) return true; + if (!Array.isArray(props)) return false; + for (let i = 0; i < props.length; i++) { + if (props[i].name === name) return true; } return false; } @@ -1175,12 +1175,12 @@ export class JsonMetadata { if (!type) return []; const props = this.getProperties(type); const dynamicProps = this.getDynamicPropertiesByObj(obj); - for(let i = dynamicProps.length -1; i >= 0; i --) { - if(this.findProperty(type, dynamicProps[i].name)) { + for (let i = dynamicProps.length - 1; i >= 0; i--) { + if (this.findProperty(type, dynamicProps[i].name)) { dynamicProps.splice(i, 1); } } - if(dynamicProps.length === 0) return props; + if (dynamicProps.length === 0) return props; return [].concat(props).concat(dynamicProps); } @@ -1211,15 +1211,15 @@ export class JsonMetadata { } public getDynamicPropertiesByObj(obj: any, dynamicType: string = null): Array { if (!obj || !obj.getType) return []; - if(!!obj.getDynamicProperties) return obj.getDynamicProperties(); - if(!obj.getDynamicType && !dynamicType) return []; + if (!!obj.getDynamicProperties) return obj.getDynamicProperties(); + if (!obj.getDynamicType && !dynamicType) return []; const dType = !!dynamicType ? dynamicType : obj.getDynamicType(); return this.getDynamicPropertiesByTypes(obj.getType(), dType); } public getDynamicPropertiesByTypes(objType: string, dynamicType: string, invalidNames?: Array): Array { if (!dynamicType) return []; const cacheType = dynamicType + "-" + objType; - if(this.dynamicPropsCache[cacheType]) return this.dynamicPropsCache[cacheType]; + if (this.dynamicPropsCache[cacheType]) return this.dynamicPropsCache[cacheType]; var dynamicProps = this.getProperties(dynamicType); if (!dynamicProps || dynamicProps.length == 0) return []; const hash: any = {}; @@ -1228,7 +1228,7 @@ export class JsonMetadata { hash[props[i].name] = props[i]; } const res = []; - if(!invalidNames) invalidNames = []; + if (!invalidNames) invalidNames = []; for (let i = 0; i < dynamicProps.length; i++) { const dProp = dynamicProps[i]; if (invalidNames.indexOf(dProp.name) < 0 && this.canAddDybamicProp(dProp, hash[dProp.name])) { @@ -1239,12 +1239,12 @@ export class JsonMetadata { return res; } private canAddDybamicProp(dProp: JsonObjectProperty, orgProp: JsonObjectProperty): boolean { - if(!orgProp) return true; - if(dProp === orgProp) return false; + if (!orgProp) return true; + if (dProp === orgProp) return false; let classInfo = dProp.classInfo; - while(classInfo && classInfo.parentName) { + while (classInfo && classInfo.parentName) { dProp = this.findProperty(classInfo.parentName, dProp.name); - if(dProp && dProp === orgProp) return true; + if (dProp && dProp === orgProp) return true; classInfo = !!dProp ? dProp.classInfo : undefined; } return false; @@ -1279,7 +1279,7 @@ export class JsonMetadata { propertyName: string ): JsonObjectProperty { const cl = this.findClass(className); - return !!cl ? cl.findProperty(propertyName): null; + return !!cl ? cl.findProperty(propertyName) : null; } public findProperties( className: string, @@ -1287,7 +1287,7 @@ export class JsonMetadata { ): Array { var result = new Array(); const cl = this.findClass(className); - if(!cl) return result; + if (!cl) return result; for (var i = 0; i < propertyNames.length; i++) { var prop = cl.findProperty(propertyNames[i]); if (prop) { @@ -1365,7 +1365,7 @@ export class JsonMetadata { } public getRequiredProperties(name: string): Array { const metaClass = this.findClass(name); - if(!metaClass) return []; + if (!metaClass) return []; const props = metaClass.getRequiredProperties(); var res = []; for (var i = 0; i < props.length; i++) { @@ -1482,14 +1482,14 @@ export class JsonMetadata { private generateLocStrClass(): any { const props: any = {}; const locProp = Serializer.findProperty("survey", "locale"); - if(!!locProp) { + if (!!locProp) { const choices = locProp.getChoices(null); - if(Array.isArray(choices)) { - if(choices.indexOf("en") < 0) { + if (Array.isArray(choices)) { + if (choices.indexOf("en") < 0) { choices.splice(0, 0, "en"); } choices.splice(0, 0, "default"); - choices.forEach(l => { if(!!l) { props[l] = { type: "string" }; } }); + choices.forEach(l => { if (!!l) { props[l] = { type: "string" }; } }); } } return { @@ -1502,42 +1502,44 @@ export class JsonMetadata { if (!classInfo) return; const schemaProperties = classSchema.properties; const requiredProps = []; - if(classInfo.name === "question" || classInfo.name === "panel") { + if (classInfo.name === "question" || classInfo.name === "panel") { schemaProperties.type = { type: "string" }; requiredProps.push("type"); } for (let i = 0; i < classInfo.properties.length; i++) { const prop = classInfo.properties[i]; - if(!!classInfo.parentName && !!Serializer.findProperty(classInfo.parentName, prop.name)) continue; + if (!!classInfo.parentName && !!Serializer.findProperty(classInfo.parentName, prop.name)) continue; schemaProperties[prop.name] = this.generateSchemaProperty(prop, schemaDef, isRoot); - if(prop.isRequired) requiredProps.push(prop.name); + if (prop.isRequired) requiredProps.push(prop.name); } - if(requiredProps.length > 0) { + if (requiredProps.length > 0) { classSchema.required = requiredProps; } } private generateSchemaProperty(prop: JsonObjectProperty, schemaDef: any, isRoot: boolean): any { - if(prop.isLocalizable) { - return { oneOf: [ - { "type": "string" }, - { "$ref": this.getChemeRefName("locstring", isRoot) } - ] }; + if (prop.isLocalizable) { + return { + oneOf: [ + { "type": "string" }, + { "$ref": this.getChemeRefName("locstring", isRoot) } + ] + }; } const propType = prop.schemaType(); const refType = prop.schemaRef(); - var res: any = { }; - if(!!propType) { + var res: any = {}; + if (!!propType) { res.type = propType; } if (prop.hasChoices) { const enumRes = prop.getChoices(null); - if(Array.isArray(enumRes) && enumRes.length > 0) { + if (Array.isArray(enumRes) && enumRes.length > 0) { res.enum = this.getChoicesValues(enumRes); } } - if(!!refType) { - if(propType === "array") { - if(prop.className === "string") { + if (!!refType) { + if (propType === "array") { + if (prop.className === "string") { res.items = { type: prop.className }; } else { res.items = { $ref: this.getChemeRefName(prop.className, isRoot) }; @@ -1586,14 +1588,14 @@ export class JsonMetadata { } else { res.properties = chemaProps.properties; } - if(Array.isArray(chemaProps.required)) { + if (Array.isArray(chemaProps.required)) { res.required = chemaProps.required; } } private getChoicesValues(enumRes: Array): Array { const res = new Array(); enumRes.forEach(item => { - if(typeof item === "object" && item.value !== undefined) { + if (typeof item === "object" && item.value !== undefined) { res.push(item.value); } else { res.push(item); @@ -1732,12 +1734,12 @@ export class JsonObject { if (!property && needAddErrors) { this.addNewError(new JsonUnknownPropertyError(key.toString(), objType), jsonObj, obj); } - if(property) { + if (property) { const dProps = property.dependsOn; - if(Array.isArray(dProps)) { + if (Array.isArray(dProps)) { parentProps[key] = true; dProps.forEach(propKey => { - if(!parentProps[propKey]) { + if (!parentProps[propKey]) { this.setPropertyValueToObj(jsonObj, obj, propKey, properties, processedProps, parentProps, objType, false, options); } }); @@ -1760,10 +1762,10 @@ export class JsonObject { ); } const storeDefaults = options === true; - if(!options || options === true) { - options = { }; + if (!options || options === true) { + options = {}; } - if(storeDefaults) { + if (storeDefaults) { options.storeDefaults = storeDefaults; } this.propertiesToJson( @@ -1789,7 +1791,7 @@ export class JsonObject { props: Array ): Array { if (!obj.getDynamicPropertyName && !obj.getDynamicProperties) return props; - if(obj.getDynamicPropertyName) { + if (obj.getDynamicPropertyName) { const dynamicPropName = obj.getDynamicPropertyName(); if (!dynamicPropName) return props; if (dynamicPropName && jsonObj[dynamicPropName]) { @@ -1810,19 +1812,19 @@ export class JsonObject { } } public valueToJson(obj: any, result: any, prop: JsonObjectProperty, options?: ISaveToJSONOptions): void { - if(!options) options = {}; + if (!options) options = {}; if (prop.isSerializable === false || (prop.isLightSerializable === false && this.lightSerializing)) return; - if(options.version && !prop.isAvailableInVersion(options.version)) return; + if (options.version && !prop.isAvailableInVersion(options.version)) return; this.valueToJsonCore(obj, result, prop, options); } private valueToJsonCore(obj: any, result: any, prop: JsonObjectProperty, options?: ISaveToJSONOptions): void { const serProp = prop.getSerializedProperty(obj, options.version); - if(serProp && serProp !== prop) { + if (serProp && serProp !== prop) { this.valueToJsonCore(obj, result, serProp, options); return; } var value = prop.getSerializableValue(obj, options.storeDefaults); - if(value === undefined) return; + if (value === undefined) return; if (this.isValueArray(value)) { var arrValue = []; for (var i = 0; i < value.length; i++) { @@ -1832,7 +1834,7 @@ export class JsonObject { } else { value = this.toJsonObjectCore(value, prop, options); } - if(value === undefined || value === null) return; + if (value === undefined || value === null) return; const name = prop.getSerializedName(options.version); var hasValue = typeof obj["getPropertyValue"] === "function" && @@ -1850,10 +1852,10 @@ export class JsonObject { property.setValue(obj, value, this); return; } - if(property.isArray && !Array.isArray(value) && !!value) { + if (property.isArray && !Array.isArray(value) && !!value) { value = [value]; const propName = !!jsonObj && property.alternativeName && !!jsonObj[property.alternativeName] ? property.alternativeName : property.name; - this.addNewError(new JsonRequiredArrayPropertyError(propName, obj.getType()), !!jsonObj ? jsonObj: value, obj); + this.addNewError(new JsonRequiredArrayPropertyError(propName, obj.getType()), !!jsonObj ? jsonObj : value, obj); } if (this.isValueArray(value)) { this.valueToArray(value, obj, property.name, property, options); @@ -1867,8 +1869,8 @@ export class JsonObject { if (!newObj.error) { if (property != null) { property.setValue(obj, value, this); - if(!!options && options.validatePropertyValues) { - if(!property.validateValue(value)) { + if (!!options && options.validatePropertyValues) { + if (!property.validateValue(value)) { this.addNewError(new JsonIncorrectPropertyValueError(property, value), jsonObj, obj); } } @@ -1878,7 +1880,7 @@ export class JsonObject { } } private removePosOnValueToJson(property: JsonObjectProperty, value: any): any { - if(!property.isCustom || !value) return value; + if (!property.isCustom || !value) return value; this.removePosFromObj(value); return value; } @@ -1894,11 +1896,11 @@ export class JsonObject { this.removePosFromObj(obj[i]); } } - if(typeof obj !== "object") return; + if (typeof obj !== "object") return; if (!!obj[JsonObject.positionPropertyName]) { delete obj[JsonObject.positionPropertyName]; } - for(let key in obj) { + for (let key in obj) { this.removePosFromObj(obj[key]); } } @@ -1924,10 +1926,10 @@ export class JsonObject { if (!res) { res = value[JsonObject.typePropertyName]; } - if(!res) return res; + if (!res) return res; res = res.toLowerCase(); const classNamePart = property.classNamePart; - if(classNamePart && res.indexOf(classNamePart) < 0) { + if (classNamePart && res.indexOf(classNamePart) < 0) { res += classNamePart; } return res; @@ -1964,7 +1966,7 @@ export class JsonObject { private getRequiredError(obj: any, jsonValue: any): JsonError { if (!obj.getType || typeof obj.getData === "function") return null; const metaClass = Serializer.findClass(obj.getType()); - if(!metaClass) return null; + if (!metaClass) return null; const props = metaClass.getRequiredProperties(); if (!Array.isArray(props)) return null; for (var i = 0; i < props.length; i++) { @@ -1980,9 +1982,9 @@ export class JsonObject { error.jsonObj = jsonObj; error.element = element; this.errors.push(error); - if(!jsonObj) return; + if (!jsonObj) return; const posObj = jsonObj[JsonObject.positionPropertyName]; - if(!posObj) return; + if (!posObj) return; error.at = posObj.start; error.end = posObj.end; } diff --git a/packages/survey-core/src/localizablestring.ts b/packages/survey-core/src/localizablestring.ts index 3d377ffa7c..a93f3556b9 100644 --- a/packages/survey-core/src/localizablestring.ts +++ b/packages/survey-core/src/localizablestring.ts @@ -1,5 +1,5 @@ import { Helpers } from "./helpers"; -import { surveyLocalization, getSurveyString } from "./surveyStrings"; +import { surveyLocalization, getLocaleString } from "./surveyStrings"; import { settings } from "./settings"; import { Base, EventBase } from "./base"; import { Serializer } from "./jsonobject"; @@ -50,7 +50,7 @@ export class LocalizableString implements ILocalizableString { } private _allowLineBreaks: boolean; public get allowLineBreaks(): boolean { - if(this._allowLineBreaks === undefined) { + if (this._allowLineBreaks === undefined) { this._allowLineBreaks = false; if (!!this.name && this.owner instanceof SurveyElementCore) { this._allowLineBreaks = Serializer.findProperty((this.owner as SurveyElementCore).getType(), this.name)?.type == "text"; @@ -156,7 +156,7 @@ export class LocalizableString implements ILocalizableString { } private getLocalizationStr(): string { const name = this.getLocalizationName(); - return !!name ? getSurveyString(name, this.locale) : ""; + return !!name ? getLocaleString(name, this.locale) : ""; } public get hasHtml(): boolean { return this.hasHtmlValue(); @@ -195,9 +195,9 @@ export class LocalizableString implements ILocalizableString { } public setLocaleText(loc: string, value: string): void { loc = this.getValueLoc(loc); - if(!!loc && value === undefined) { + if (!!loc && value === undefined) { const oldValue = this.getValue(loc); - if(oldValue !== undefined) { + if (oldValue !== undefined) { this.deleteValue(loc); this.fireStrChanged(loc, oldValue); } @@ -288,7 +288,7 @@ export class LocalizableString implements ILocalizableString { ) return (this).values[keys[0]]; const res: any = {}; - for(let key in this.values) { + for (let key in this.values) { res[key] = this.values[key]; } return res; @@ -301,7 +301,7 @@ export class LocalizableString implements ILocalizableString { this.values = {}; this.htmlValues = {}; if (value === null || value === undefined) return; - if(isLoading) { + if (isLoading) { if (typeof value === "string") { this.values[settings.defaultLocaleName] = value; } else { diff --git a/packages/survey-core/src/question_baseselect.ts b/packages/survey-core/src/question_baseselect.ts index 9c75a7d7fd..e8586a9ab3 100644 --- a/packages/survey-core/src/question_baseselect.ts +++ b/packages/survey-core/src/question_baseselect.ts @@ -4,7 +4,7 @@ import { ISurveyImpl, ISurvey, ISurveyData, IPlainDataOptions, IValueItemCustomP import { SurveyModel } from "./survey"; import { IQuestionPlainData, Question } from "./question"; import { ItemValue } from "./itemvalue"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { OtherEmptyError } from "./error"; import { ChoicesRestful } from "./choicesRestful"; import { LocalizableString } from "./localizablestring"; @@ -2119,7 +2119,7 @@ Serializer.addClass( { name: "choices:itemvalue[]", uniqueProperty: "value", baseValue: function () { - return getSurveyString("choices_Item"); + return getLocaleString("choices_Item"); }, dependsOn: "choicesFromQuestion", visibleIf: (obj: any) => { diff --git a/packages/survey-core/src/question_matrix.ts b/packages/survey-core/src/question_matrix.ts index e74d31d0a2..4cb9ef2dcf 100644 --- a/packages/survey-core/src/question_matrix.ts +++ b/packages/survey-core/src/question_matrix.ts @@ -4,7 +4,7 @@ import { QuestionMatrixBaseModel } from "./martixBase"; import { JsonObject, Serializer } from "./jsonobject"; import { Base } from "./base"; import { SurveyError } from "./survey-error"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { RequiredInAllRowsError, EachRowUniqueError } from "./error"; import { QuestionFactory } from "./questionfactory"; import { LocalizableString, ILocalizableOwner } from "./localizablestring"; @@ -46,7 +46,7 @@ export class MatrixRowModel extends Base { this.registerPropertyChangedHandlers(["value"], () => { if (this.data) this.data.onMatrixRowChanged(this); }); - if(this.data && this.data.hasErrorInRow(this)) { + if (this.data && this.data.hasErrorInRow(this)) { this.hasError = true; } } @@ -63,7 +63,7 @@ export class MatrixRowModel extends Base { return this.getPropertyValue("value"); } public set value(val: any) { - if(!this.isReadOnly) { + if (!this.isReadOnly) { this.setValueDirectly(this.data.getCorrectedRowValue(val)); } } @@ -110,7 +110,7 @@ export class MatrixCells extends Base { public onValuesChanged: () => void; private locNotification: boolean; private valuesChanged(): void { - if(!this.locNotification && !!this.onValuesChanged) { + if (!this.locNotification && !!this.onValuesChanged) { this.onValuesChanged(); } } @@ -132,9 +132,9 @@ export class MatrixCells extends Base { res = this.createString(); res.setJson(this.getCellLocData(row, col)); res.onGetTextCallback = (str: string): string => { - if(!str) { + if (!str) { const column = ItemValue.getItemByValue(this.columns, col); - if(column) { + if (column) { return column.locText.getJson() || column.value; } } @@ -150,7 +150,7 @@ export class MatrixCells extends Base { private get defaultRowValue() { return settings.matrix.defaultRowName; } private getCellLocData(row: any, col: any): any { let data = this.getCellLocDataFromValue(row, col); - if(data) return data; + if (data) return data; return this.getCellLocDataFromValue(this.defaultRowValue, col); } private getCellLocDataFromValue(row: any, column: any): any { @@ -164,7 +164,7 @@ export class MatrixCells extends Base { } public setCellText(row: any, column: any, val: string): void { const loc = this.getCellLocCore(row, column); - if(loc) { + if (loc) { loc.text = val; } } @@ -217,7 +217,7 @@ export class MatrixCells extends Base { const resRow: { [index: string]: any } = {}; const rowValues = this.values[row]; for (let col in rowValues) { - if(row === this.defaultRowValue || !defaultRow || defaultRow[col] !== rowValues[col]) { + if (row === this.defaultRowValue || !defaultRow || defaultRow[col] !== rowValues[col]) { resRow[col] = rowValues[col]; } } @@ -427,7 +427,7 @@ export class QuestionMatrixModel super.onRowsChanged(); } protected getVisibleRows(): Array { - if(!!this.generatedVisibleRows) return this.generatedVisibleRows; + if (!!this.generatedVisibleRows) return this.generatedVisibleRows; const result = new Array(); let val = this.value; if (!val) val = {}; @@ -512,10 +512,10 @@ export class QuestionMatrixModel if (!isOnValueChanged || this.hasCssError()) { const rowsErrors = { noValue: false, isNotUnique: false }; this.checkErrorsAllRows(fireCallback, rowsErrors); - if(rowsErrors.noValue) { + if (rowsErrors.noValue) { errors.push(new RequiredInAllRowsError(null, this)); } - if(rowsErrors.isNotUnique) { + if (rowsErrors.isNotUnique) { errors.push(new EachRowUniqueError(null, this)); } } @@ -533,38 +533,38 @@ export class QuestionMatrixModel const rowsUnique = this.eachRowUnique; res.noValue = false; res.isNotUnique = false; - if(modifyErrors) { + if (modifyErrors) { this.errorsInRow = undefined; } - if(!rowsRequired && !rowsUnique) return; + if (!rowsRequired && !rowsUnique) return; const hash: HashTable = {}; for (var i = 0; i < rows.length; i++) { const val = rows[i].value; let isEmpty = this.isValueEmpty(val); const isNotUnique = rowsUnique && (!isEmpty && hash[val] === true); isEmpty = isEmpty && rowsRequired; - if(modifyErrors && (isEmpty || isNotUnique)) { + if (modifyErrors && (isEmpty || isNotUnique)) { this.addErrorIntoRow(rows[i]); } - if(!isEmpty) { + if (!isEmpty) { hash[val] = true; } res.noValue = res.noValue || isEmpty; res.isNotUnique = res.isNotUnique || isNotUnique; } - if(modifyErrors) { + if (modifyErrors) { rows.forEach(row => { row.hasError = this.hasErrorInRow(row); }); } } private addErrorIntoRow(row: MatrixRowModel): void { - if(!this.errorsInRow) this.errorsInRow = {}; + if (!this.errorsInRow) this.errorsInRow = {}; this.errorsInRow[row.name] = true; row.hasError = true; } private refreshRowsErrors(): void { - if(!this.errorsInRow) return; + if (!this.errorsInRow) return; this.checkErrorsAllRows(true, { noValue: false, isNotUnique: false }); } protected getIsAnswered(): boolean { @@ -579,7 +579,7 @@ export class QuestionMatrixModel this.onMatrixRowCreated(row); return row; } - protected onMatrixRowCreated(row: MatrixRowModel) {} + protected onMatrixRowCreated(row: MatrixRowModel) { } protected setQuestionValue(newValue: any, updateIsAnswered: boolean = true) { super.setQuestionValue(newValue, this.isRowChanging || updateIsAnswered); if (!this.generatedVisibleRows || this.generatedVisibleRows.length == 0) @@ -699,14 +699,14 @@ export class QuestionMatrixModel for (var i = 0; i < rows.length; i++) { var key = rows[i].value; if (!!updatedData[key]) { - if(inRows && !rows[i].isVisible || inColumns && !this.getVisibleColumnByValue(updatedData[key])) { + if (inRows && !rows[i].isVisible || inColumns && !this.getVisibleColumnByValue(updatedData[key])) { delete updatedData[key]; } else { newData[key] = updatedData[key]; } } } - if(inCorrectRows) { + if (inCorrectRows) { updatedData = newData; } if (this.isTwoValueEquals(updatedData, this.value)) return; @@ -793,14 +793,14 @@ Serializer.addClass( "rowTitleWidth", { name: "columns:itemvalue[]", uniqueProperty: "value", - baseValue: function() { - return getSurveyString("matrix_column"); + baseValue: function () { + return getLocaleString("matrix_column"); }, }, { name: "rows:itemvalue[]", uniqueProperty: "value", - baseValue: function() { - return getSurveyString("matrix_row"); + baseValue: function () { + return getLocaleString("matrix_row"); }, }, { name: "cells:cells", serializationProperty: "cells" }, @@ -814,7 +814,7 @@ Serializer.addClass( "hideIfRowsEmpty:boolean", { name: "cellComponent", visible: false, default: "survey-matrix-cell" } ], - function() { + function () { return new QuestionMatrixModel(""); }, "matrixbase" diff --git a/packages/survey-core/src/question_rating.ts b/packages/survey-core/src/question_rating.ts index 0656e1c1ad..09e7c3e4d3 100644 --- a/packages/survey-core/src/question_rating.ts +++ b/packages/survey-core/src/question_rating.ts @@ -4,7 +4,7 @@ import { property, propertyArray, Serializer } from "./jsonobject"; import { QuestionFactory } from "./questionfactory"; import { LocalizableString } from "./localizablestring"; import { settings } from "./settings"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { CssClassBuilder } from "./utils/cssClassBuilder"; import { Base } from "./base"; import { mergeValues } from "./utils/utils"; @@ -169,7 +169,7 @@ export class QuestionRatingModel extends Question { this.rateValues.splice(this.rateCount, this.rateValues.length - this.rateCount); } else { for (let i = this.rateValues.length; i < this.rateCount; i++) { - this.rateValues.push(new ItemValue(getSurveyString("choices_Item") + (i + 1))); + this.rateValues.push(new ItemValue(getLocaleString("choices_Item") + (i + 1))); } } } @@ -982,7 +982,7 @@ Serializer.addClass( { name: "rateValues:itemvalue[]", baseValue: function () { - return getSurveyString("choices_Item"); + return getLocaleString("choices_Item"); }, category: "rateValues", visibleIf: function (obj: any) { diff --git a/packages/survey-core/src/questionfactory.ts b/packages/survey-core/src/questionfactory.ts index fdd495a712..085472ccaa 100644 --- a/packages/survey-core/src/questionfactory.ts +++ b/packages/survey-core/src/questionfactory.ts @@ -1,26 +1,26 @@ import { HashTable } from "./helpers"; import { Question } from "./question"; import { IElement } from "./base-interfaces"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; import { Serializer } from "./jsonobject"; import { ComponentCollection } from "./question_custom"; export class QuestionFactory { public static Instance: QuestionFactory = new QuestionFactory(); public static get DefaultChoices(): string[] { - const choice = getSurveyString("choices_Item"); + const choice = getLocaleString("choices_Item"); return [choice + "1", choice + "2", choice + "3"]; } public static get DefaultColums(): string[] { - var colName = getSurveyString("matrix_column") + " "; + var colName = getLocaleString("matrix_column") + " "; return [colName + "1", colName + "2", colName + "3"]; } public static get DefaultRows(): string[] { - var rowName = getSurveyString("matrix_row") + " "; + var rowName = getLocaleString("matrix_row") + " "; return [rowName + "1", rowName + "2"]; } public static get DefaultMutlipleTextItems(): string[] { - var itemName = getSurveyString("multipletext_itemname"); + var itemName = getLocaleString("multipletext_itemname"); return [itemName + "1", itemName + "2"]; } public registerQuestion(questionType: string, questionCreator: (name: string) => Question, showInToolbox: boolean = true): void { diff --git a/packages/survey-core/src/survey-error.ts b/packages/survey-core/src/survey-error.ts index eddb624615..de97cf5096 100644 --- a/packages/survey-core/src/survey-error.ts +++ b/packages/survey-core/src/survey-error.ts @@ -1,6 +1,6 @@ import { ISurveyErrorOwner } from "./base-interfaces"; import { LocalizableString } from "./localizablestring"; -import { getSurveyString } from "./surveyStrings"; +import { getLocaleString } from "./surveyStrings"; export class SurveyError { private locTextValue: LocalizableString; @@ -8,10 +8,10 @@ export class SurveyError { constructor( public text: string = null, protected errorOwner: ISurveyErrorOwner = null - ) {} + ) { } public equals(error: SurveyError): boolean { - if(!error || !error.getErrorType) return false; - if(this.getErrorType() !== error.getErrorType()) return false; + if (!error || !error.getErrorType) return false; + if (this.getErrorType() !== error.getErrorType()) return false; return this.text === error.text && this.visible === error.visible; } public get locText(): LocalizableString { @@ -38,14 +38,14 @@ export class SurveyError { return ""; } protected getLocale(): string { - return !!this.errorOwner ? this.errorOwner.getLocale(): ""; + return !!this.errorOwner ? this.errorOwner.getLocale() : ""; } protected getLocalizationString(locStrName: string): string { - return getSurveyString(locStrName, this.getLocale()); + return getLocaleString(locStrName, this.getLocale()); } public onUpdateErrorTextCallback: (error: SurveyError) => void = undefined; public updateText(): void { - if(this.onUpdateErrorTextCallback) { + if (this.onUpdateErrorTextCallback) { this.onUpdateErrorTextCallback(this); } this.locText.text = this.getText(); diff --git a/packages/survey-core/src/surveyStrings.ts b/packages/survey-core/src/surveyStrings.ts index d2b28108b3..a6baa38c37 100644 --- a/packages/survey-core/src/surveyStrings.ts +++ b/packages/survey-core/src/surveyStrings.ts @@ -16,7 +16,7 @@ export var surveyLocalization = { this.locales[loc] = strings; this.localeNames[loc] = name; this.localeNamesInEnglish[loc] = nameInEngish; - if(direction !== undefined) { + if (direction !== undefined) { this.localeDirections[loc] = direction; } }, @@ -41,31 +41,31 @@ export var surveyLocalization = { const locs = new Array(); const addLocaleCore = (locName: string): void => { const strs = this.locales[locName]; - if(!!strs) locs.push(strs); + if (!!strs) locs.push(strs); }; const addLocale = (locName: string): void => { - if(!locName) return; + if (!locName) return; addLocaleCore(locName); const index = locName.indexOf("-"); - if(index < 1) return; + if (index < 1) return; locName = locName.substring(0, index); addLocaleCore(locName); }; addLocale(locale); addLocale(this.currentLocale); addLocale(this.defaultLocale); - if(this.defaultLocale !== "en") { + if (this.defaultLocale !== "en") { addLocaleCore("en"); } - for(let i = 0; i < locs.length; i ++) { + for (let i = 0; i < locs.length; i++) { const res = locs[i][strName]; - if(res !== undefined) return res; + if (res !== undefined) return res; } return this.onGetExternalString(strName, locale); }, getLocaleName(loc: string, inEnglish?: boolean): string { - if(!loc) return ""; - if(inEnglish === undefined) inEnglish = this.showNamesInEnglish; + if (!loc) return ""; + if (inEnglish === undefined) inEnglish = this.showNamesInEnglish; const firstNames = inEnglish ? this.localeNamesInEnglish : this.localeNames; const secondNames = inEnglish ? this.localeNames : this.localeNamesInEnglish; return firstNames[loc] || secondNames[loc] || loc; @@ -98,7 +98,7 @@ export var surveyLocalization = { onGetExternalString: function (name: string, locale: string): string { return undefined; } }; -export function getSurveyString(strName: string, locale: string = null): string { +export function getLocaleString(strName: string, locale: string = null): string { return surveyLocalization.getString(strName, locale); } export var surveyStrings = englishStrings; diff --git a/packages/survey-core/src/utils/utils.ts b/packages/survey-core/src/utils/utils.ts index 57f8fb75ce..4bfd103474 100644 --- a/packages/survey-core/src/utils/utils.ts +++ b/packages/survey-core/src/utils/utils.ts @@ -1,7 +1,7 @@ import { LocalizableString } from "../localizablestring"; import { settings, ISurveyEnvironment } from "./../settings"; import { IDialogOptions } from "../popup"; -import { getSurveyString } from "../surveyStrings"; +import { getLocaleString } from "../surveyStrings"; import { PopupBaseViewModel } from "../popup-view-model"; import { DomDocumentHelper, DomWindowHelper } from "../global_variables_utils"; @@ -165,14 +165,14 @@ function wrapUrlForBackgroundImage(url: string): string { return !!url ? ["url(", url, ")"].join("") : ""; } function isBase64URL(url: string): boolean { - if(typeof url == "string") { + if (typeof url == "string") { return /^data:((?:\w+\/(?:(?!;).)+)?)((?:;[^;]+?)*),(.+)$/.test(url); } return null; } // old-name: new-name -const renamedIcons:any = { +const renamedIcons: any = { "changecamera": "flip-24x24", "clear": "clear-24x24", "cancel": "cancel-24x24", @@ -327,7 +327,7 @@ export function getNewIconName(iconName: string): string { return prefix + result; } -export function getCustomNewIconNameIfExists(iconName: string):string { +export function getCustomNewIconNameIfExists(iconName: string): string { // only for settings.customIcons["icon-import"] = "icon-export"; feature let result = (settings.customIcons)[iconName]; if (result) return getNewIconName(result); @@ -375,8 +375,8 @@ function createSvg( titleElement.textContent = title; } export function getSafeUrl(url: string): string { - if(!url) return url; - if(url.toLocaleLowerCase().indexOf("javascript:")> -1) return encodeURIComponent(url); + if (!url) return url; + if (url.toLocaleLowerCase().indexOf("javascript:") > -1) return encodeURIComponent(url); return url; } @@ -499,7 +499,7 @@ function preventDefaults(event: any) { event.stopPropagation(); } function classesToSelector(str: string): string { - if(!str) return str; + if (!str) return str; const re = /\s*?([\w-]+)\s*?/g; return str.replace(re, ".$1"); } @@ -618,9 +618,9 @@ export function showConfirmDialog(message: string, callback: (res: boolean) => v const toolbar = popupViewModel.footerToolbar; const applyBtn = toolbar.getActionById("apply"); const cancelBtn = toolbar.getActionById("cancel"); - cancelBtn.title = getSurveyString("cancel", locale); + cancelBtn.title = getLocaleString("cancel", locale); cancelBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sd-btn sd-btn--small"; - applyBtn.title = applyTitle || getSurveyString("ok", locale); + applyBtn.title = applyTitle || getLocaleString("ok", locale); applyBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sv-popup__button--danger sd-btn sd-btn--small sd-btn--danger"; configConfirmDialog(popupViewModel); return true; @@ -651,7 +651,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: const commonItemsInOldMap = new Map(); oldValue.forEach((item) => { const itemKey = getKey(item); - if(!oldItemsMap.has(itemKey)) { + if (!oldItemsMap.has(itemKey)) { oldItemsMap.set(getKey(item), item); } else { //if keys are set incorrectly do not process comparing @@ -660,7 +660,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: }); newValue.forEach((item) => { const itemKey = getKey(item); - if(!newItemsMap.has(itemKey)) { + if (!newItemsMap.has(itemKey)) { newItemsMap.set(itemKey, item); } else { //if keys are set incorrectly do not process comparing @@ -672,7 +672,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: //calculating addedItems and items that exist in both arrays newItemsMap.forEach((item, key) => { - if(!oldItemsMap.has(key)) { + if (!oldItemsMap.has(key)) { addedItems.push(item); } else { commonItemsInNewMap.set(key, commonItemsInNewMap.size); @@ -682,7 +682,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: //calculating deletedItems and items that exist in both arrays oldItemsMap.forEach((item, key) => { - if(!newItemsMap.has(key)) { + if (!newItemsMap.has(key)) { deletedItems.push(item); } else { commonItemsInOldMap.set(key, commonItemsInOldMap.size); @@ -694,7 +694,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: commonItemsInNewMap.forEach((index, key) => { const oldIndex = commonItemsInOldMap.get(key); const item = newItemsMap.get(key); - if(oldIndex !== index) reorderedItems.push({ item: item, movedForward: oldIndex < index }); + if (oldIndex !== index) reorderedItems.push({ item: item, movedForward: oldIndex < index }); }); //calculating merged array if multiple operations are applied at once @@ -703,7 +703,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: let commonItemsIndex = 0; const commonItemsKeysOrder = Array.from(commonItemsInNewMap.keys()); oldValue.forEach((item, index) => { - if(commonItemsInNewMap.has(getKey(item))) { + if (commonItemsInNewMap.has(getKey(item))) { oldItemsWithCorrectOrder[index] = newItemsMap.get(commonItemsKeysOrder[commonItemsIndex]); commonItemsIndex++; } else { @@ -715,8 +715,8 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: let tempValuesArray: Array = []; oldItemsWithCorrectOrder.forEach((item) => { const itemKey = getKey(item); - if(newItemsMap.has(itemKey)) { - if(tempValuesArray.length > 0) { + if (newItemsMap.has(itemKey)) { + if (tempValuesArray.length > 0) { valuesToInsertBeforeKey.set(itemKey, tempValuesArray); tempValuesArray = []; } @@ -726,7 +726,7 @@ export function compareArrays(oldValue: Array, newValue: Array, getKey: }); const mergedItems = new Array(); newItemsMap.forEach((item, key) => { - if(valuesToInsertBeforeKey.has(key)) { + if (valuesToInsertBeforeKey.has(key)) { valuesToInsertBeforeKey.get(key).forEach((item) => { mergedItems.push(item); }); @@ -751,10 +751,10 @@ interface IVerticalDimensions { } export function getVerticalDimensions(el: HTMLElement): IVerticalDimensions { - if(DomDocumentHelper.isAvailable()) { + if (DomDocumentHelper.isAvailable()) { const { paddingTop, paddingBottom, borderTopWidth, borderBottomWidth, marginTop, marginBottom, boxSizing } = DomDocumentHelper.getComputedStyle(el); let heightTo = el.offsetHeight + "px"; - if(boxSizing == "content-box") { + if (boxSizing == "content-box") { let heightPx = el.offsetHeight; [borderBottomWidth, borderTopWidth, paddingBottom, paddingTop].forEach((style) => { heightPx -= parseFloat(style); @@ -790,7 +790,7 @@ export function prepareElementForVerticalAnimation(el: HTMLElement): void { } export function cleanHtmlElementAfterAnimation(el: HTMLElement): void { - if(Array.isArray((el as any)["__sv_created_properties"])) { + if (Array.isArray((el as any)["__sv_created_properties"])) { (el as any)["__sv_created_properties"].forEach((propertyName: string) => { el.style.removeProperty(propertyName); }); diff --git a/packages/survey-core/tests/questionFileTests.ts b/packages/survey-core/tests/questionFileTests.ts index 2fa0921556..457b580d5a 100644 --- a/packages/survey-core/tests/questionFileTests.ts +++ b/packages/survey-core/tests/questionFileTests.ts @@ -1,7 +1,7 @@ import { SurveyModel } from "../src/survey"; import { QuestionFileModel } from "../src/question_file"; import { QuestionPanelDynamicModel } from "../src/question_paneldynamic"; -import { getSurveyString } from "../src/surveyStrings"; +import { getLocaleString } from "../src/surveyStrings"; import { settings } from "../src/settings"; import { StylesManager } from "@legacy/stylesmanager"; import { Serializer } from "../src/jsonobject"; @@ -605,51 +605,51 @@ QUnit.test("Writable captions", function (assert) { /** * The remove file confirmation message template. */ - assert.equal(q.confirmRemoveMessage, getSurveyString("confirmRemoveFile"), "The remove file confirmation message template default"); + assert.equal(q.confirmRemoveMessage, getLocaleString("confirmRemoveFile"), "The remove file confirmation message template default"); q.confirmRemoveMessage += "_new"; - assert.equal(q.confirmRemoveMessage, getSurveyString("confirmRemoveFile") + "_new", "The remove file confirmation message template new"); + assert.equal(q.confirmRemoveMessage, getLocaleString("confirmRemoveFile") + "_new", "The remove file confirmation message template new"); /** * The remove all files confirmation message. */ - assert.equal(q.confirmRemoveAllMessage, getSurveyString("confirmRemoveAllFiles"), "The remove all files confirmation message default"); + assert.equal(q.confirmRemoveAllMessage, getLocaleString("confirmRemoveAllFiles"), "The remove all files confirmation message default"); q.confirmRemoveAllMessage += "_new"; - assert.equal(q.confirmRemoveAllMessage, getSurveyString("confirmRemoveAllFiles") + "_new", "The remove all files confirmation message new"); + assert.equal(q.confirmRemoveAllMessage, getLocaleString("confirmRemoveAllFiles") + "_new", "The remove all files confirmation message new"); /** * The no file chosen caption for modern theme. */ - assert.equal(q.noFileChosenCaption, getSurveyString("noFileChosen"), "The no file chosen caption for modern theme default"); + assert.equal(q.noFileChosenCaption, getLocaleString("noFileChosen"), "The no file chosen caption for modern theme default"); q.noFileChosenCaption += "_new"; - assert.equal(q.noFileChosenCaption, getSurveyString("noFileChosen") + "_new", "The no file chosen caption for modern theme new"); + assert.equal(q.noFileChosenCaption, getLocaleString("noFileChosen") + "_new", "The no file chosen caption for modern theme new"); /** * The choose files button caption for modern theme. */ - assert.equal(q.chooseButtonCaption, getSurveyString("chooseFileCaption"), "The choose files button caption for modern theme default"); + assert.equal(q.chooseButtonCaption, getLocaleString("chooseFileCaption"), "The choose files button caption for modern theme default"); q.chooseButtonCaption += "_new"; - assert.equal(q.chooseButtonCaption, getSurveyString("chooseFileCaption") + "_new", "The choose files button caption for modern theme new"); + assert.equal(q.chooseButtonCaption, getLocaleString("chooseFileCaption") + "_new", "The choose files button caption for modern theme new"); /** * The clean files button caption. */ - assert.equal(q.clearButtonCaption, getSurveyString("clearCaption"), "The clean files button caption default"); + assert.equal(q.clearButtonCaption, getLocaleString("clearCaption"), "The clean files button caption default"); q.clearButtonCaption += "_new"; - assert.equal(q.clearButtonCaption, getSurveyString("clearCaption") + "_new", "The clean files button caption new"); + assert.equal(q.clearButtonCaption, getLocaleString("clearCaption") + "_new", "The clean files button caption new"); /** * The remove file button caption. */ - assert.equal(q.removeFileCaption, getSurveyString("removeFileCaption"), "The remove file button caption default"); + assert.equal(q.removeFileCaption, getLocaleString("removeFileCaption"), "The remove file button caption default"); q.removeFileCaption += "_new"; - assert.equal(q.removeFileCaption, getSurveyString("removeFileCaption") + "_new", "The remove file button caption new"); + assert.equal(q.removeFileCaption, getLocaleString("removeFileCaption") + "_new", "The remove file button caption new"); /** * The loading file input title. */ - assert.equal(q.loadingFileTitle, getSurveyString("loadingFile"), "The loading file input title default"); + assert.equal(q.loadingFileTitle, getLocaleString("loadingFile"), "The loading file input title default"); q.loadingFileTitle += "_new"; - assert.equal(q.loadingFileTitle, getSurveyString("loadingFile") + "_new", "The loading file input title new"); + assert.equal(q.loadingFileTitle, getLocaleString("loadingFile") + "_new", "The loading file input title new"); /** * The choose file input title. */ - assert.equal(q.chooseFileTitle, getSurveyString("chooseFile"), "The choose file input title default"); + assert.equal(q.chooseFileTitle, getLocaleString("chooseFile"), "The choose file input title default"); q.chooseFileTitle += "_new"; - assert.equal(q.chooseFileTitle, getSurveyString("chooseFile") + "_new", "The choose file input title new"); + assert.equal(q.chooseFileTitle, getLocaleString("chooseFile") + "_new", "The choose file input title new"); }); diff --git a/tests/ko/survey_kotests.ts b/tests/ko/survey_kotests.ts index 0610e6fada..b5bd6a688e 100644 --- a/tests/ko/survey_kotests.ts +++ b/tests/ko/survey_kotests.ts @@ -13,7 +13,7 @@ import { Page, Panel, QuestionRow } from "../../src/knockout/kopage"; import { CustomWidgetCollection } from "../../packages/survey-core/src//questionCustomWidgets"; import { koTemplate } from "../../src/knockout/templateText"; import { QuestionMatrixDynamic } from "../../src/knockout/koquestion_matrixdynamic"; -import { getSurveyString } from "../../packages/survey-core/src//surveyStrings"; +import { getLocaleString } from "../../packages/survey-core/src//surveyStrings"; import { QuestionRating } from "../../src/knockout/koquestion_rating"; import { QuestionImagePicker } from "../../src/knockout/koquestion_imagepicker"; import { ImageItemValue } from "../../packages/survey-core/src//question_imagepicker"; @@ -441,7 +441,7 @@ QUnit.test("Localization, otherItem", function (assert) { var defaultText = q1.visibleChoices[2].locText["koRenderedHtml"](); assert.equal( q1.visibleChoices[2].locText["koRenderedHtml"](), - getSurveyString("otherItemText"), + getLocaleString("otherItemText"), "use default locale" ); survey.locale = "de";