Skip to content

Commit

Permalink
Add translations for menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Aug 9, 2024
1 parent bf47ad7 commit 973371d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
48 changes: 28 additions & 20 deletions app/assets/javascripts/components/input_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html, PropertyValues, TemplateResult } from "lit";
import jspreadsheet, { Column, JspreadsheetInstance } from "jspreadsheet-ce";
import { createRef, ref, Ref } from "lit/directives/ref.js";
import { DodonaElement } from "components/meta/dodona_element";
import { fetch } from "utilities";
import { fetch, ready } from "utilities";
import { i18n } from "i18n/i18n";
import { Tooltip } from "bootstrap";

Expand Down Expand Up @@ -97,12 +97,21 @@ export class ScoreItemInputTable extends DodonaElement {
];
}

protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
async initTable(): Promise<void> {
// Wait for translations to be present
await ready;

this.table = jspreadsheet(this.tableRef.value, {
root: this,
data: this.data,
columns: this.columnConfig,
text: {
copy: i18n.t("js.score_items.jspreadsheet.copy"),
deleteSelectedRows: i18n.t("js.score_items.jspreadsheet.deleteSelectedRows"),
insertANewRowAfter: i18n.t("js.score_items.jspreadsheet.insertNewRowAfter"),
insertANewRowBefore: i18n.t("js.score_items.jspreadsheet.insertNewRowBefore"),
paste: i18n.t("js.score_items.jspreadsheet.paste"),
},
about: false,
allowDeleteColumn: false,
allowDeleteRow: true,
Expand All @@ -121,12 +130,28 @@ export class ScoreItemInputTable extends DodonaElement {
allowExport: false,
});

// init tooltips
this.columnConfig.forEach((column, index) => {
const td = this.tableRef.value.querySelector(`thead td[data-x="${index}"]`);
if (td && column.tooltip) {
td.setAttribute("title", column.tooltip);
new Tooltip(td);
}
});


// update description column width when the window is resized
new ResizeObserver(() => {
this.table.setWidth(2, this.descriptionColWidth);
}).observe(this.tableRef.value);
}

protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);

this.initTable();
}

validate(): boolean {
// Remove all error classes
this.tableRef.value.querySelectorAll("td.error").forEach(cell => {
Expand Down Expand Up @@ -193,18 +218,6 @@ export class ScoreItemInputTable extends DodonaElement {
}
}

updateTitlesAndTooltips(): void {
this.columnConfig.forEach((column, index) => {
this.table.setHeader(index, column.title);

const td = this.tableRef.value.querySelector(`thead td[data-x="${index}"]`);
if (td && column.tooltip) {
td.setAttribute("title", column.tooltip);
new Tooltip(td);
}
});
}

cancel(): void {
if (this.table) {
this.table.setData(this.data);
Expand All @@ -214,11 +227,6 @@ export class ScoreItemInputTable extends DodonaElement {


render(): TemplateResult {
if (this.table && this.tableRef.value) {
// Reset column headers as language might have changed
this.updateTitlesAndTooltips();
}

return html`
${this.hasErrors ? html`<div class="alert alert-danger">${i18n.t("js.score_items.validation_warning")}</div>` : ""}
<div style="width: 100%" ${ref(this.tableRef)}></div>
Expand Down
14 changes: 14 additions & 0 deletions app/assets/javascripts/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@
"deleted_warning": "You have deleted one or more score items. This will also delete all scores for these items.",
"description": "Description",
"description_help": "A description is optional. Markdown formatting can be used. This is visible to the students.",
"jspreadsheet": {
"copy": "Copy...",
"deleteSelectedRows": "Delete selected rows",
"insertNewRowAfter": "Insert new row after",
"insertNewRowBefore": "Insert new row before",
"paste": "Paste..."
},
"maximum": "Maximum",
"maximum_help": "The maximum grade for this score item. The grade should be greater than 0, and works in increments of 0.25.",
"modified_warning": "You have changed the maximum score of one or more score items. This will mark all completed evaluations with this score item as uncompleted.",
Expand Down Expand Up @@ -887,6 +894,13 @@
"deleted_warning": "Je hebt een of meerdere scoreonderdelen verwijderd. Dit zal ook de bijhorende scores van de studenten verwijderen.",
"description": "Beschrijving",
"description_help": "Een beschrijving is optioneel en kan in Markdown geschreven worden. Dit is zichtbaar voor de studenten.",
"jspreadsheet": {
"copy": "Kopiëer...",
"deleteSelectedRows": "Verwijder geselecteerde rijen",
"insertNewRowAfter": "Voeg nieuwe rij toe na deze",
"insertNewRowBefore": "Voeg nieuwe rij toe voor deze",
"paste": "Plak..."
},
"maximum": "Maximum",
"maximum_help": "De maximumscore voor dit scoreonderdeel. Dit moet een positief getal zijn en gaat in stappen van 0.25.",
"modified_warning": "Je hebt de maximumscore van een of meerdere scoreonderdelen aangepast. Alle afgewerkte evaluaties met dit scoreonderdeel zullen terug als onafgewerkt gemarkeerd worden.",
Expand Down
6 changes: 6 additions & 0 deletions config/locales/js/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,9 @@ en:
validation_warning: All score items must have a name and a maximum score, and the maximum score must be greater than 0.
save: Save
cancel: Cancel
jspreadsheet:
copy: Copy...
deleteSelectedRows: Delete selected rows
insertNewRowAfter: Insert new row after
insertNewRowBefore: Insert new row before
paste: Paste...
7 changes: 6 additions & 1 deletion config/locales/js/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,10 @@ nl:
modified_warning: "Je hebt de maximumscore van een of meerdere scoreonderdelen aangepast. Alle afgewerkte evaluaties met dit scoreonderdeel zullen terug als onafgewerkt gemarkeerd worden."
deleted_warning: "Je hebt een of meerdere scoreonderdelen verwijderd. Dit zal ook de bijhorende scores van de studenten verwijderen."
validation_warning: "Alle scoreonderdelen moeten een naam en een maximumscore hebben. De maximumscore moet een positief getal zijn."

jspreadsheet:
copy: Kopiëer...
deleteSelectedRows: Verwijder geselecteerde rijen
insertNewRowAfter: Voeg nieuwe rij toe na deze
insertNewRowBefore: Voeg nieuwe rij toe voor deze
paste: Plak...

0 comments on commit 973371d

Please sign in to comment.