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

ICustomQuestionTypeConfiguration.title is not localizable fix #5904 #5921

Merged
merged 1 commit into from
Oct 1, 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
14 changes: 13 additions & 1 deletion packages/survey-creator-core/src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ export class QuestionToolbox
const iconName: string = json.iconName ? json.iconName : QuestionToolbox.defaultIconName;
let title: string = editorLocalization.getString("qt." + json.name);
if (!title || title == json.name) {
title = json.title;
title = this.getTitleFromJsonTitle(json.title, json.name);
}
if (!title) {
title = json.name;
Expand All @@ -1285,6 +1285,18 @@ export class QuestionToolbox
});
return this.getOrCreateToolboxItem(item);
}
private getTitleFromJsonTitle(title: any, name: string): string {
if(!title) return title;
if(typeof title === "string") return title;
if(typeof title !== "object") return title;
for(let key in title) {
const loc = editorLocalization.locales[key];
if(title[key] && loc && loc.qt) {
loc.qt[name] = title[key];
}
}
return editorLocalization.getString("qt." + name);
}
private getQuestionJSON(question: any): any {
var json = new JsonObject().toJsonObject(question);
json.type = question.getType();
Expand Down
24 changes: 24 additions & 0 deletions packages/survey-creator-core/tests/toolbox.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { settings } from "../src/creator-settings";
import { IQuestionToolboxItem, QuestionToolbox, QuestionToolboxItem } from "../src/toolbox";
import { CreatorTester } from "./creator-tester";
import { ToolboxToolViewModel } from "../src/components/toolbox/toolbox-tool";
import { editorLocalization } from "../src/editorLocalization";
export * from "../src/localization/english";
export * from "../src/localization/german";

test("toolbox support options", (): any => {
var allTypes = ElementFactory.Instance.getAllToolboxTypes();
Expand Down Expand Up @@ -851,4 +854,25 @@ test("Toolbox item removeSubitem function", (): any => {
ratingItem.removeSubitem(ratingItem.items[0]);
expect(ratingItem.hasSubItems).toBe(false);
expect(ratingItem.component).toBe("");
});

test("ICustomQuestionTypeConfiguration.title should support a localizable, Bug#5904", (): any => {
editorLocalization.locales["en"] = editorLocalization.getLocale();
expect(editorLocalization.locales["en"]).toBeTruthy();
expect(editorLocalization.locales["de"]).toBeTruthy();
ComponentCollection.Instance.clear();
ComponentCollection.Instance.add(<any>{
name: "newquestion",
title: { en: "New Question en", de: "New Question de" },
questionJSON: {
type: "dropdown",
choices: [1, 2, 3, 4, 5]
}
});
const creator = new CreatorTester({ questionTypes: ["text", "checkbox"] });
const item = creator.toolbox.getItemByName("newquestion") as QuestionToolboxItem;
expect(item.title).toBe("New Question en");
creator.locale = "de";
expect(item.title).toBe("New Question de");
ComponentCollection.Instance.clear();
});
Loading