Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update localication strings in prop grid, toolbox and test plugin fix… #6024

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class TabTestPlugin implements ICreatorPlugin {
const options = {
showPagesInTestSurveyTab: this.creator.showPagesInTestSurveyTab,
};
this.testAgainAction.locStrsChanged();
this.model.testAgainAction = this.testAgainAction;
this.model.prevPageAction = this.prevPageAction;
this.model.nextPageAction = this.nextPageAction;
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-creator-core/src/property-grid/search-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { QuestionToolbox } from "../toolbox";

export abstract class SearchManager extends Base {
public searchActionBar: ActionContainer = new ActionContainer();
public filterStringPlaceholder;
public get filterStringPlaceholder(): string { return this.getFilterStringPlaceholder(); }
@property() filterString: string;
@property() isVisible: boolean;
@property() matchCounterText: string;
Expand Down Expand Up @@ -34,6 +34,7 @@ export abstract class SearchManager extends Base {
}

protected abstract setFiterString(newValue: string, oldValue: string);
protected abstract getFilterStringPlaceholder(): string;

protected onPropertyValueChanged(name: string, oldValue: any, newValue: any) {
super.onPropertyValueChanged(name, oldValue, newValue);
Expand All @@ -56,7 +57,6 @@ export abstract class SearchManager extends Base {

export class SearchManagerToolbox extends SearchManager {
@property() toolbox: QuestionToolbox;
public filterStringPlaceholder = getLocString("ed.toolboxFilteredTextPlaceholder");
protected setFiterString(newValue: string, oldValue: string) {
this.toolbox.showSeparators = !newValue;
this.toolbox.items.forEach(item => item.visible = item.hasText(newValue));
Expand All @@ -66,7 +66,7 @@ export class SearchManagerToolbox extends SearchManager {
category.empty = category.items.filter(item => item.visible).length == 0;
});
}

protected getFilterStringPlaceholder(): string { return getLocString("ed.toolboxFilteredTextPlaceholder"); }
public clearFilterString(): void {
this.filterString = "";
this.toolbox.rootElement.querySelector("input").focus();
Expand All @@ -78,8 +78,8 @@ export class SearchManagerPropertyGrid extends SearchManager {

private currentMatchIndex: number;
private currentMatch: Question;
public filterStringPlaceholder = getLocString("ed.propertyGridFilteredTextPlaceholder");
public propertyGridNoResultsFound = getLocString("ed.propertyGridNoResultsFound");
protected getFilterStringPlaceholder(): string { return getLocString("ed.propertyGridFilteredTextPlaceholder"); }
public get propertyGridNoResultsFound(): string { return getLocString("ed.propertyGridNoResultsFound"); }

@property() survey: SurveyModel;
@property() isVisible: boolean;
Expand Down
22 changes: 18 additions & 4 deletions packages/survey-creator-core/src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export class QuestionToolboxCategory extends Base {
* An object of this class is returned by the `QuestionToolbox`'s [`getItemByName(name)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#getItemByName) method.
*/
export class QuestionToolboxItem extends Action implements IQuestionToolboxItem {
public propName: string;
public propValue: string;
static getItemClassNames(iconName?: string): string {
return new CssClassBuilder()
.append("svc-toolbox__item")
Expand Down Expand Up @@ -393,7 +395,7 @@ export class QuestionToolbox
@property({ defaultValue: false }) private showCategoryTitlesValue: boolean;
private dragOrClickHelper: DragOrClickHelper;

public toolboxNoResultsFound = getLocString("ed.toolboxNoResultsFound");
public get toolboxNoResultsFound() { return getLocString("ed.toolboxNoResultsFound"); }

//koItems = ko.observableArray();
/**
Expand Down Expand Up @@ -797,11 +799,12 @@ export class QuestionToolbox
isCopied: false,
component: QuestionToolbox.defaultItemComponent
});
innerItem.propName = propName;
innerItem.propValue = ch;
return innerItem;
});
return newItems;
}

/**
* Adds a new item to the Toolbox.
* @param item A [toolbox item configuration](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem).
Expand Down Expand Up @@ -927,15 +930,26 @@ export class QuestionToolbox
}
public updateTitles(): void {
this.actions.forEach(action => {
this.updateActionTitle(action);
this.updateActionTitle(action.innerItem);
this.updateToolboxItemTitle(action);
});
if (Array.isArray(this.categories)) {
this.categories.forEach(category => {
category.title = this.getCategoryTitle(category.name);
});
}
}
private updateToolboxItemTitle(item: QuestionToolboxItem): void {
this.updateActionTitle(item);
this.updateActionTitle(item.innerItem);
if(!Array.isArray(item.items)) return;
item.items.forEach(subItem => {
const propName = subItem.propName;
const propValue = subItem.propValue;
if(!!propName && !!propValue) {
subItem.title = editorLocalization.getPropertyValueInEditor(propName, propValue);
}
});
}
private updateActionTitle(action: IAction): void {
const newTitle = editorLocalization.getString("qt." + action.id);
if (!!newTitle && newTitle !== action.id) {
Expand Down
22 changes: 21 additions & 1 deletion packages/survey-creator-core/tests/tabs/test.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { SurveyResultsItemModel, SurveyResultsModel } from "../../src/components
import { IAction, ListModel, Question, QuestionDropdownModel, SurveyModel, StylesManager, _setIsTouch } from "survey-core";
import { TabTestPlugin } from "../../src/components/tabs/test-plugin";
import { SurveySimulatorModel, simulatorDevices } from "../../src/components/simulator";
import { editorLocalization } from "../../src/editorLocalization";
import { editorLocalization, getLocString } from "../../src/editorLocalization";
export * from "../../src/localization/german";

import "survey-core/survey.i18n";

Expand Down Expand Up @@ -1096,4 +1097,23 @@ test("Suppress NavigateToUrl notification using allow option", (): any => {
model.survey.doComplete();
expect(onNavigateToUrlLog).toBe("->javascript:alert(2)->javascript:alert(2)");
expect(notificationsLog).toBe("->You had to navigate to 'javascript:alert(2)'.");
});
test("The Preview Survey button text is not translated Bug#6016", (): any => {
const deText = "Testumfrage wiederholen";
const loc: any = editorLocalization.getLocale("de");
expect(loc).toBeTruthy();
if(!loc.ed) loc.ed = {};
loc.ed.testSurveyAgain = deText;
editorLocalization.currentLocale = "en";
const creator: CreatorTester = new CreatorTester();
expect(creator.locale).toBe("en");
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
expect(testPlugin.model).toBeFalsy();
creator.locale = "de";
creator.activeTab = "test";
expect(creator.locale).toBe("de");
expect(editorLocalization.currentLocale).toBe("de");
expect(getLocString("ed.testSurveyAgain")).toBe(deText);
expect(testPlugin.model.testAgainAction.title).toBe(deText);
creator.locale = "";
});
11 changes: 10 additions & 1 deletion packages/survey-creator-core/tests/toolbox.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,4 +876,13 @@ test("Check toolbox getAnimatedElement methods", (): any => {
expect(toolbox.isFlyoutToCompactRunning).toBeFalsy();
expect(toolbox.classNames.indexOf(isFlyoutToCompactRunningClass) >= 0).toBeFalsy();
surveySettings.animationEnabled = false;
});
});
test("Update subitems on locale change, Bug#6014", (): any => {
const creator = new CreatorTester({ questionTypes: ["text", "checkbox"] });
creator.locale = "de";
const checkbox = creator.toolbox.getItemByName("checkbox") as QuestionToolboxItem;
expect(checkbox.locTitle.renderedHtml).toBe("Auswahl");
const text = creator.toolbox.getItemByName("text") as QuestionToolboxItem;
expect(text.getSubitemByName("color").locTitle.renderedHtml).toBe("Farbe");
creator.locale = "en";
});