From 479d4cb4bb2620467a872576b4b48f9f4f67deea Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 1 Nov 2024 15:08:20 +0200 Subject: [PATCH 1/2] Update localication strings in prop grid, toolbox and test plugin fix #6014, #6016 --- .../src/components/tabs/test-plugin.ts | 1 + .../src/property-grid/search-manager.ts | 10 ++++----- packages/survey-creator-core/src/toolbox.ts | 22 +++++++++++++++---- .../tests/tabs/test.tests.ts | 10 +++++++++ .../tests/toolbox.tests.ts | 11 +++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/survey-creator-core/src/components/tabs/test-plugin.ts b/packages/survey-creator-core/src/components/tabs/test-plugin.ts index cf9f5153f5..b0121bcbf7 100644 --- a/packages/survey-creator-core/src/components/tabs/test-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/test-plugin.ts @@ -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; diff --git a/packages/survey-creator-core/src/property-grid/search-manager.ts b/packages/survey-creator-core/src/property-grid/search-manager.ts index 9a289965f6..88db4efb60 100644 --- a/packages/survey-creator-core/src/property-grid/search-manager.ts +++ b/packages/survey-creator-core/src/property-grid/search-manager.ts @@ -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; @@ -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); @@ -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)); @@ -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(); @@ -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; diff --git a/packages/survey-creator-core/src/toolbox.ts b/packages/survey-creator-core/src/toolbox.ts index 699113aed8..3bd5289eb1 100644 --- a/packages/survey-creator-core/src/toolbox.ts +++ b/packages/survey-creator-core/src/toolbox.ts @@ -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") @@ -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(); /** @@ -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). @@ -927,8 +930,7 @@ 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 => { @@ -936,6 +938,18 @@ export class QuestionToolbox }); } } + 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) { diff --git a/packages/survey-creator-core/tests/tabs/test.tests.ts b/packages/survey-creator-core/tests/tabs/test.tests.ts index bf047d726f..5f870887ad 100644 --- a/packages/survey-creator-core/tests/tabs/test.tests.ts +++ b/packages/survey-creator-core/tests/tabs/test.tests.ts @@ -5,6 +5,7 @@ import { IAction, ListModel, Question, QuestionDropdownModel, SurveyModel, Style import { TabTestPlugin } from "../../src/components/tabs/test-plugin"; import { SurveySimulatorModel, simulatorDevices } from "../../src/components/simulator"; import { editorLocalization } from "../../src/editorLocalization"; +import "../../src/localization/german"; import "survey-core/survey.i18n"; @@ -1096,4 +1097,13 @@ 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 creator: CreatorTester = new CreatorTester(); + const testPlugin: TabTestPlugin = creator.getPlugin("test"); + creator.locale = "de"; + testPlugin.activate(); + const model: TestSurveyTabViewModel = testPlugin.model; + expect(model.testAgainAction.locTitle.renderedHtml).toBe("Testumfrage wiederholen"); + creator.locale = "en"; }); \ No newline at end of file diff --git a/packages/survey-creator-core/tests/toolbox.tests.ts b/packages/survey-creator-core/tests/toolbox.tests.ts index 4fa52c2b21..fb994cceb7 100644 --- a/packages/survey-creator-core/tests/toolbox.tests.ts +++ b/packages/survey-creator-core/tests/toolbox.tests.ts @@ -876,4 +876,13 @@ test("Check toolbox getAnimatedElement methods", (): any => { expect(toolbox.isFlyoutToCompactRunning).toBeFalsy(); expect(toolbox.classNames.indexOf(isFlyoutToCompactRunningClass) >= 0).toBeFalsy(); surveySettings.animationEnabled = false; -}); \ No newline at end of file +}); +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"; +}); From 7ffdbfb9343cd9ef0644042992eec682966bbda6 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 1 Nov 2024 16:42:47 +0200 Subject: [PATCH 2/2] FIx unit test --- .../tests/tabs/test.tests.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/survey-creator-core/tests/tabs/test.tests.ts b/packages/survey-creator-core/tests/tabs/test.tests.ts index 5f870887ad..b1a6526b3e 100644 --- a/packages/survey-creator-core/tests/tabs/test.tests.ts +++ b/packages/survey-creator-core/tests/tabs/test.tests.ts @@ -4,8 +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 "../../src/localization/german"; +import { editorLocalization, getLocString } from "../../src/editorLocalization"; +export * from "../../src/localization/german"; import "survey-core/survey.i18n"; @@ -1099,11 +1099,21 @@ test("Suppress NavigateToUrl notification using allow option", (): any => { 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 = creator.getPlugin("test"); + expect(testPlugin.model).toBeFalsy(); creator.locale = "de"; - testPlugin.activate(); - const model: TestSurveyTabViewModel = testPlugin.model; - expect(model.testAgainAction.locTitle.renderedHtml).toBe("Testumfrage wiederholen"); - creator.locale = "en"; + 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 = ""; }); \ No newline at end of file