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

Texts within cells of a Single-Select Matrix Rubric cannot be transla… #5861

Merged
merged 2 commits into from
Sep 9, 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
32 changes: 31 additions & 1 deletion packages/survey-creator-core/src/components/tabs/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
PopupBaseViewModel, IDialogOptions, settings as surveySettings,
MatrixDropdownColumn,
CssClassBuilder,
createPopupModelWithListModel
createPopupModelWithListModel,
MatrixCells,
QuestionMatrixModel
} from "survey-core";
import { unparse, parse } from "papaparse";
import { editorLocalization } from "../../editorLocalization";
Expand Down Expand Up @@ -443,8 +445,36 @@ export class TranslationGroup extends TranslationItemBase {
this.createGroups(value, property);
}
}
this.createMatrixCellsGroup();
this.sortItems();
}
private createMatrixCellsGroup(): void {
Serializer.getPropertiesByObj(this.obj).forEach(prop => {
if(prop.type === "cells" && this.canShowProperty(prop, true)) {
this.createMatrixCellsGroupCore(prop);
}
});
}
private createMatrixCellsGroupCore(prop: JsonObjectProperty): void {
const cells = <MatrixCells>this.obj[prop.name];
if(cells.isEmpty) return;
const matrix = <QuestionMatrixModel>this.obj;
const root = new TranslationGroup(prop.name, cells, this.translation, editorLocalization.getPropertyName(prop.name));
const defaultName = surveySettings.matrix.defaultRowName;
const rows = [{ value: defaultName, text: editorLocalization.getString("qt.default") }];
matrix.rows.forEach(row => rows.push({ value: row.value, text: row.text }));
rows.forEach(row => {
matrix.columns.forEach(col => {
const locStr = cells.getCellLocText(row.value, col);
if(!!locStr) {
const name = editorLocalization.getPropertyName(row.text, "") + ", " + editorLocalization.getPropertyName(col.title);
const item = new TranslationItem(name, locStr, "", this.translation, locStr);
root.items.push(item);
}
});
});
this.addNewGroup(root);
}
private sortItems() {
if (!settings.translation.sortByName) return;
this.itemValues.sort(function (
Expand Down
41 changes: 40 additions & 1 deletion packages/survey-creator-core/tests/tabs/translation.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Serializer, SurveyModel, surveyLocalization, Base, QuestionDropdownModel, PanelModel, QuestionMatrixDropdownModel, QuestionTextModel, QuestionCommentModel, ListModel, Action, IAction, ItemValue, QuestionMatrixDynamicModel } from "survey-core";
import { Serializer, SurveyModel, surveyLocalization, Base, QuestionDropdownModel, PanelModel, QuestionMatrixDropdownModel, QuestionTextModel, QuestionCommentModel, ListModel, Action, IAction, ItemValue, QuestionMatrixDynamicModel, QuestionMatrixModel } from "survey-core";
import { Translation, TranslationItem } from "../../src/components/tabs/translation";
import { TabTranslationPlugin } from "../../src/components/tabs/translation-plugin";
import { EmptySurveyCreatorOptions, settings } from "../../src/creator-settings";
Expand Down Expand Up @@ -2144,3 +2144,42 @@ test("onTranslationStringVisibility for imageLink, Issue #5734", (): void => {
expect(items).toHaveLength(4);
expect(items[1].name).toBe("spanishUrl.imageLink");
});
test("Translate matrix cells, Bug#8759", () => {
const survey = new SurveyModel({
elements: [
{
type: "matrix",
name: "q1",
columns: ["col1", "col2"],
rows: ["row1", "row2"],
cells: {
"default": {
"col1": "col1_default",
"col2": "col2_default"
},
row1: { col1: "row1_col1" },
row2: { col2: "row2_col2" }
}
}
]
});
const translation = new Translation(survey);
translation.reset();
let group = translation.root.groups[0];
expect(group.items).toHaveLength(1);
expect(group.items[0].name).toEqual("q1");
group = group.groups[0];
expect(group.groups).toHaveLength(3);
group = group.groups[2];
expect(group.name).toBe("cells");
expect(group.text).toBe("Cells");
expect(group.items).toHaveLength(4);
const item = <TranslationItem>group.items[3];
expect(item.text).toBe("Row 2, Col 2");
expect(item.getLocText("")).toBe("row2_col2");
item.setLocText("de", "de_row2_col2");
const matrix = <QuestionMatrixModel>survey.getQuestionByName("q1");
const locstr = matrix.cells.getCellDisplayLocText("row2", matrix.columns[1]);
expect(locstr).toBeTruthy();
expect(locstr.getLocaleText("de")).toBe("de_row2_col2");
});