Skip to content

Commit 45ddeb9

Browse files
committed
Survey and Page Title and Description placeholders are not translated properly when switching creator.locale at runtime fix #6695 (#6705)
1 parent a9c6e7a commit 45ddeb9

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
@@ -137,6 +137,28 @@ test("StringEditorViewModelBase page title placeholder for started page", () =>
137137
expect(editor.placeholder).toBe("Page 1");
138138
});
139139

140+
test("StringEditorViewModelBase page title placeholder and changing creator locale on the fly, Bug#6695", () => {
141+
const deutschStrings: any = {
142+
pe: {
143+
surveyTitlePlaceholder: "Umfragetitel eingeben"
144+
}
145+
};
146+
editorLocalization.locales["de"] = deutschStrings;
147+
const creator = new CreatorTester();
148+
creator.JSON = {
149+
pages: [
150+
{ elements: [{ type: "text" }] },
151+
{ elements: [{ type: "text" }] }
152+
]
153+
};
154+
const survey = creator.survey;
155+
const page1 = survey.pages[0];
156+
const surveyTitleEdtor: StringEditorViewModelBase = new StringEditorViewModelBase(survey.locTitle, creator);
157+
expect(surveyTitleEdtor.placeholder).toBe("Survey Title");
158+
creator.locale = "de";
159+
expect(surveyTitleEdtor.placeholder).toBe("Umfragetitel eingeben");
160+
});
161+
140162
test("Logo css", () => {
141163
const creator = new CreatorTester();
142164
var logo = new LogoImageViewModel(creator, null);

0 commit comments

Comments
 (0)