From c3e6cf6c9d4ac735db684ff8bace4ee1cc6e0933 Mon Sep 17 00:00:00 2001 From: "matti.bat" <138713607+mattibat@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:20:35 +0100 Subject: [PATCH] Label the branch in the language of the structogram --- packages/struktolab/src/common/svg-renderer.js | 9 +++++++-- packages/struktolab/src/editor/struktolab-editor.js | 4 ++-- packages/struktolab/src/renderer/struktolab-renderer.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/struktolab/src/common/svg-renderer.js b/packages/struktolab/src/common/svg-renderer.js index 24d7112..690b7d8 100644 --- a/packages/struktolab/src/common/svg-renderer.js +++ b/packages/struktolab/src/common/svg-renderer.js @@ -1,3 +1,5 @@ +import { KEYWORDS_DE } from "./pseudocode-parser.js"; + const SVG_NS = "http://www.w3.org/2000/svg"; const COLORS = { @@ -52,6 +54,7 @@ const COLORS = { }; let COLOR_MODE = "color"; +let KEYWORDS = KEYWORDS_DE; function getColor(nodeType) { return COLORS[COLOR_MODE](nodeType); @@ -457,11 +460,11 @@ function renderNode(node, x, y, width, fontSize, availH) { // True/False labels below slopes const smallFS = fontSize * 0.8; elements.push( - textEl("Wahr", x + PADDING_X, slopeBottom, labelRowH, smallFS, null), + textEl(KEYWORDS.true, x + PADDING_X, slopeBottom, labelRowH, smallFS, null), ); elements.push( textEl( - "Falsch", + KEYWORDS.false, x + width - PADDING_X, slopeBottom, labelRowH, @@ -926,6 +929,7 @@ function renderNode(node, x, y, width, fontSize, availH) { * @param {number} [options.width=600] - SVG coordinate width (used for layout calculations) * @param {number} [options.fontSize=14] - Font size in px * @param {string} [options.colorMode] - "color" (default) or "bw" for black-and-white colors + * @param {Object} [options.keywords=KEYWORDS_DE] - Keyword map for the true/false labels * @returns {SVGSVGElement} */ export function renderStructogramSVG(tree, options = {}) { @@ -934,6 +938,7 @@ export function renderStructogramSVG(tree, options = {}) { if (options.colorMode && COLORS[options.colorMode]) { COLOR_MODE = options.colorMode; } + KEYWORDS = options.keywords || KEYWORDS_DE; const totalHeight = measureHeight(tree, fontSize, width); const h = totalHeight || 40; diff --git a/packages/struktolab/src/editor/struktolab-editor.js b/packages/struktolab/src/editor/struktolab-editor.js index e807bec..c5e07c0 100644 --- a/packages/struktolab/src/editor/struktolab-editor.js +++ b/packages/struktolab/src/editor/struktolab-editor.js @@ -1044,7 +1044,7 @@ class StruktolabEditor extends HTMLElement { // moment a move starts used to grow the diagram and slide the node out // from under the pointer, which is the one thing a drag must not do. setInsertNodeHeight(0); - const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode }); + const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() }); svg.setAttribute("role", "group"); svg.setAttribute("aria-label", this._t("structogram")); @@ -2713,7 +2713,7 @@ class StruktolabEditor extends HTMLElement { // Render a clean SVG (no insert-node space, no overlays) setInsertNodeHeight(0); - const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode }); + const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() }); setInsertNodeHeight(0); const serializer = new XMLSerializer(); diff --git a/packages/struktolab/src/renderer/struktolab-renderer.js b/packages/struktolab/src/renderer/struktolab-renderer.js index 23c44a0..a8bcb97 100644 --- a/packages/struktolab/src/renderer/struktolab-renderer.js +++ b/packages/struktolab/src/renderer/struktolab-renderer.js @@ -179,7 +179,7 @@ class StruktolabRenderer extends HTMLElement { this._container.removeChild(this._container.firstChild); } - const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode }); + const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() }); this._container.appendChild(svg); } }