From 2d914dd9e01406e6c4972b36e7e3c1f4415a27d2 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 24 Jan 2025 16:11:21 +0200 Subject: [PATCH 1/2] Page title and description placeholders and question adorner texts are not updated when changing a creator.locale at runtime fix #6441 --- .../designer/localization_dynamic.ts | 17 +++++++++++++++++ .../components/action-container-view-model.ts | 8 +++++++- .../survey-creator-core/src/creator-base.ts | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 functionalTests/designer/localization_dynamic.ts diff --git a/functionalTests/designer/localization_dynamic.ts b/functionalTests/designer/localization_dynamic.ts new file mode 100644 index 0000000000..a246483052 --- /dev/null +++ b/functionalTests/designer/localization_dynamic.ts @@ -0,0 +1,17 @@ +import { url, setJSON, setSurveyProp } from "../helper"; +import { ClientFunction, Selector } from "testcafe"; +const title = "Localization UI"; +const customLogicTabName = "Miner Logik"; + +fixture(title) + .page(url) + .beforeEach(async (t) => { + await t.maximizeWindow(); + }); + +test("Change Creator.locale property", async (t) => { + await setJSON({ elements: [{ type: "checkbox", name: "question1" }] }); + await t.click(Selector("[data-name='question1']")); + await setSurveyProp("locale", "de"); + await t.expect(Selector(".svc-survey-element-toolbar-item__title--with-icon").withText("Auswahl").exists).ok(); +}); \ No newline at end of file diff --git a/packages/survey-creator-core/src/components/action-container-view-model.ts b/packages/survey-creator-core/src/components/action-container-view-model.ts index 34a9609987..95394303cb 100644 --- a/packages/survey-creator-core/src/components/action-container-view-model.ts +++ b/packages/survey-creator-core/src/components/action-container-view-model.ts @@ -305,7 +305,11 @@ export class SurveyElementAdornerBase e this.createActionContainers(); this.attachToUI(surveyElement); } - + private creatorOnLocaleChanged: (sender: Base, options: any) => void = (_, options) => { + if(this.surveyElement) { + this.updateActionsContainer(this.surveyElement); + } + }; public static GetAdorner(surveyElement: SurveyElement): V { return surveyElement.getPropertyValue(SurveyElementAdornerBase.AdornerValueName) as V; } @@ -364,6 +368,7 @@ export class SurveyElementAdornerBase e } if (this.surveyElement != surveyElement) { this.setSurveyElement(surveyElement); + this.creator.onLocaleChanded.add(this.creatorOnLocaleChanged); this.creator.sidebar.onPropertyChanged.add(this.sidebarFlyoutModeChangedFunc); this.creator.expandCollapseManager.add(this); } @@ -377,6 +382,7 @@ export class SurveyElementAdornerBase e this.rootElement = undefined; this.detachOnlyMyElement(); this.surveyElement = undefined; + this.creator.onLocaleChanded.remove(this.creatorOnLocaleChanged); this.creator.sidebar.onPropertyChanged.remove(this.sidebarFlyoutModeChangedFunc); this.creator.expandCollapseManager.remove(this); } diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 97a67bd7c4..ec567d6afb 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -1330,7 +1330,9 @@ export class SurveyCreatorModel extends Base editorLocalization.currentLocale = value; this.setPropertyValue("locale", value); this.updateLocalizedStrings(); + this.onLocaleChanded.fire(this, { locale: value }); } + public onLocaleChanded: EventBase = this.addCreatorEvent(); public updateLocalizedStrings(): void { this.toolbox.updateTitles(); this.refreshPlugin(); From f54cc0190ba37310bde47fbf0c64eb071cc61ed5 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Sun, 26 Jan 2025 15:27:41 +0200 Subject: [PATCH 2/2] Fix functional test --- functionalTests/designer/localization_dynamic.ts | 9 ++++++--- .../src/components/action-container-view-model.ts | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/functionalTests/designer/localization_dynamic.ts b/functionalTests/designer/localization_dynamic.ts index a246483052..569f74d183 100644 --- a/functionalTests/designer/localization_dynamic.ts +++ b/functionalTests/designer/localization_dynamic.ts @@ -1,7 +1,10 @@ -import { url, setJSON, setSurveyProp } from "../helper"; +import { url, setJSON } from "../helper"; import { ClientFunction, Selector } from "testcafe"; const title = "Localization UI"; -const customLogicTabName = "Miner Logik"; + +const changeLocale = ClientFunction(() => { + window["creator"].locale = "de"; +}); fixture(title) .page(url) @@ -12,6 +15,6 @@ fixture(title) test("Change Creator.locale property", async (t) => { await setJSON({ elements: [{ type: "checkbox", name: "question1" }] }); await t.click(Selector("[data-name='question1']")); - await setSurveyProp("locale", "de"); + await changeLocale(); await t.expect(Selector(".svc-survey-element-toolbar-item__title--with-icon").withText("Auswahl").exists).ok(); }); \ No newline at end of file diff --git a/packages/survey-creator-core/src/components/action-container-view-model.ts b/packages/survey-creator-core/src/components/action-container-view-model.ts index 95394303cb..e0edaf2d4c 100644 --- a/packages/survey-creator-core/src/components/action-container-view-model.ts +++ b/packages/survey-creator-core/src/components/action-container-view-model.ts @@ -308,6 +308,7 @@ export class SurveyElementAdornerBase e private creatorOnLocaleChanged: (sender: Base, options: any) => void = (_, options) => { if(this.surveyElement) { this.updateActionsContainer(this.surveyElement); + this.updateActionsProperties(); } }; public static GetAdorner(surveyElement: SurveyElement): V {