Skip to content

Commit

Permalink
Merge pull request #9077 from surveyjs/features/getSurveyString
Browse files Browse the repository at this point in the history
Add getSurveyString function
  • Loading branch information
andrewtelnov authored Nov 20, 2024
2 parents fb19134 + fa47106 commit 9c93773
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 266 deletions.
2 changes: 1 addition & 1 deletion packages/survey-core/entries/chunks/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, getLocaleString } from "../../src/surveyStrings";
// export { cultureInfo } from "../../src/cultureInfo";
export {
QuestionCustomWidget,
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-core/src/actions/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILocalizableOwner, LocalizableString } from "../localizablestring";
import { Base, ComputedUpdater } from "../base";
import { surveyLocalization } from "../surveyStrings";
import { getLocaleString } from "../surveyStrings";
import { property } from "../jsonobject";
import { IListModel, ListModel } from "../list";
import { IPopupOptionsBase, PopupModel } from "../popup";
Expand Down Expand Up @@ -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 = getLocaleString(this.locTooltipName, this.locTitle.locale);
}

//ILocalizableOwner
Expand All @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-core/src/actions/adaptive-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getLocaleString } from "../surveyStrings";

export class AdaptiveActionContainer<T extends Action = Action> extends ActionContainer<T> {
public dotsItem: Action;
Expand All @@ -16,7 +16,7 @@ export class AdaptiveActionContainer<T extends Action = Action> extends ActionCo
const hiddenItems: IAction[] = [];
actionsToHide.forEach((item) => {
if (visibleItemsCount <= 0) {
if(item.removePriority) {
if (item.removePriority) {
item.mode = "removed";
} else {
item.mode = "popup";
Expand Down Expand Up @@ -76,7 +76,7 @@ export class AdaptiveActionContainer<T extends Action = Action> extends ActionCo
innerCss: "sv-dots__item",
iconName: "icon-more",
visible: false,
tooltip: surveyLocalization.getString("more"),
tooltip: getLocaleString("more"),
}, {
items: [],
allowSelection: false
Expand Down
82 changes: 41 additions & 41 deletions packages/survey-core/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getLocaleString } from "./surveyStrings";
import { ConsoleWarnings } from "./console-warnings";

interface IExpressionRunnerInfo {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Bindings {
this.values[key] = value[key];
}
}
if(!isLoading) {
if (!isLoading) {
this.onChangedJSON(oldValue);
}
}
Expand All @@ -112,7 +112,7 @@ export class Bindings {
}
}
private onChangedJSON(oldValue: any): void {
if(this.obj) {
if (this.obj) {
this.obj.onBindingChanged(oldValue, this.getJson());
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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((<any>this).name !== (<any>obj).name) return false;
if ((<any>this).name !== (<any>obj).name) return false;
return Helpers.isTwoValueEquals(this.toJSON(), obj.toJSON(), false, true, false);
}
protected trimValue(value: any): any {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
Expand All @@ -710,25 +710,25 @@ export class Base {
return {};
}
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): 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);
}
}
protected canRunConditions(): boolean {
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<any>, properties: HashTable<any>): 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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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, <ILocalizableOwner>(<any>this), false, true);
}
public getLocale(): string {
const locOwner = this.getSurvey();
return !!locOwner ? locOwner.getLocale(): "";
return !!locOwner ? locOwner.getLocale() : "";
}
public getLocalizationString(strName: string): string {
return surveyLocalization.getString(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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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++) {
Expand Down
16 changes: 8 additions & 8 deletions packages/survey-core/src/dxSurveyService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { settings } from "./settings";
import { surveyLocalization } from "./surveyStrings";
import { getLocaleString } from "./surveyStrings";

const surveyIOSite = "surveyjs.io";
const surveyIOMaxPostSize = 65536;
Expand Down Expand Up @@ -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 () {
Expand All @@ -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;
}
Expand All @@ -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, surveyLocalization.getString("savingExceedSize", this.locale), undefined);
if (!this.canSendResult(result)) {
onSendResult(false, getLocaleString("savingExceedSize", this.locale), undefined);
} else {
this.sendResultCore(postId, result, onSendResult, clientId, isPartialCompleted);
}
Expand Down
Loading

0 comments on commit 9c93773

Please sign in to comment.