Skip to content

Commit 5628d86

Browse files
authored
Survey and Page Title and Description placeholders are not translated properly when switching creator.locale at runtime fix #6695 (#6705)
1 parent b92cf52 commit 5628d86

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/survey-creator-core/src/components/string-editor.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ export class StringEditorViewModelBase extends Base {
256256
super();
257257
this.locString = locString;
258258
this.checkMarkdownToTextConversion(this.locString.owner, this.locString.name);
259+
this.creator?.onLocaleChanded.add(this.onLocaleChanged);
259260
}
260-
261+
private onLocaleChanged = () => {
262+
this.resetPropertyValue("placeholderValue");
263+
};
261264
public afterRender() {
262265
if (this.connector.focusOnEditor) {
263266
if (this.activate()) this.connector.focusOnEditor = false;
@@ -271,6 +274,7 @@ export class StringEditorViewModelBase extends Base {
271274
}
272275

273276
public dispose(): void {
277+
this.creator?.onLocaleChanded.remove(this.onLocaleChanged);
274278
super.dispose();
275279
this.detachFromUI();
276280
}

packages/survey-creator-core/tests/tabs/designer.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@ test("StringEditorViewModelBase page title placeholder for started page", () =>
144144
expect(editorGhost.placeholder).toBe("Page 3");
145145
});
146146

147+
test("StringEditorViewModelBase page title placeholder and changing creator locale on the fly, Bug#6695", () => {
148+
const deutschStrings: any = {
149+
pe: {
150+
surveyTitlePlaceholder: "Umfragetitel eingeben"
151+
}
152+
};
153+
editorLocalization.locales["de"] = deutschStrings;
154+
const creator = new CreatorTester();
155+
creator.JSON = {
156+
pages: [
157+
{ elements: [{ type: "text" }] },
158+
{ elements: [{ type: "text" }] }
159+
]
160+
};
161+
const survey = creator.survey;
162+
const page1 = survey.pages[0];
163+
const surveyTitleEdtor: StringEditorViewModelBase = new StringEditorViewModelBase(survey.locTitle, creator);
164+
expect(surveyTitleEdtor.placeholder).toBe("Survey Title");
165+
creator.locale = "de";
166+
expect(surveyTitleEdtor.placeholder).toBe("Umfragetitel eingeben");
167+
});
168+
147169
test("Logo css", () => {
148170
const creator = new CreatorTester();
149171
var logo = new LogoImageViewModel(creator, null);

0 commit comments

Comments
 (0)