Skip to content
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
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

## Changed
### Added

- Ability to translate demo project instructions (#1230)

### Changed

- Improved status bar styling (#1221)
- Added method to translate last saved time (#1223)
- Deleting unused strings and components (#1225)

## Fixed
### Fixed

- Styling issue preventing scrolling in the sidebar (#1216)
- Styling issue on status bar on mobile (#1217)
Expand All @@ -20,11 +26,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Removed fixed size from `ProjectBar` to prevent overflow when text wraps (#1221)
- Added missing translation strings (#1222)

## Changed

- Improved status bar styling (#1221)
- Added method to translate last saved time (#1223)

## [0.30.1] - 2025-06-09

### Added
Expand Down
11 changes: 11 additions & 0 deletions public/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
"info": "Information"
},
"instructionsPanel": {
"demoInstructions": {
"title": "How instructions work",
"enablingInstructions": "Enabling instructions",
"visible": "Any text written here will be visible to students in the sidebar.",
"writingInstructions": "Writing instructions",
"markdown": "Write your instructions using [Markdown](https://www.markdownguide.org/).",
"whatYouCanDo": "What you can do",
"lists": "Lists",
"bulletPoints": "Bullet points",
"numberedSteps": "Numbered steps"
},
"emptyState": {
"addInstructions": "Add instructions",
"edits": "Like project code, students will not see any edits you make to the instructions after they have saved their version of the project.",
Expand Down
11 changes: 11 additions & 0 deletions public/translations/xx-XX.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
"info": "Informationen"
},
"instructionsPanel": {
"demoInstructions": {
"title": "So funktionieren Anweisungen",
"enablingInstructions": "Anweisungen aktivieren",
"visible": "Jeder hier geschriebene Text ist für die Schüler in der Seitenleiste sichtbar.",
"writingInstructions": "Anweisungen schreiben",
"markdown": "Schreiben Sie Ihre Anweisungen mit [Markdown](https://www.markdownguide.org/).",
"whatYouCanDo": "Was Sie tun können",
"lists": "Listen",
"bulletPoints": "Aufzählungszeichen",
"numberedSteps": "Nummerierte Schritte"
},
"emptyState": {
"addInstructions": "Anweisungen hinzufügen",
"edits": "Wie beim Projektcode sehen die Schüler keine Änderungen, die Sie an den Anweisungen vornehmen, nachdem sie ihre Version des Projekts gespeichert haben.",
Expand Down
23 changes: 12 additions & 11 deletions src/assets/markdown/demoInstructions.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# How instructions work
# {{instructionsPanel.demoInstructions.title}}

## Enabling instructions
## {{instructionsPanel.demoInstructions.enablingInstructions}}

Any text written here will be visible to students in the sidebar
{{instructionsPanel.demoInstructions.visible}}

## Writing instructions
## {{instructionsPanel.demoInstructions.writingInstructions}}

Write your instructions using [Markdown](https://www.markdownguide.org/)
### What you can do
{{instructionsPanel.demoInstructions.markdown}}

Lists:
### {{instructionsPanel.demoInstructions.whatYouCanDo}}

- Bullet points
- Bullet points
{{instructionsPanel.demoInstructions.lists}}:

1. numbered steps
2. numbered steps
- {{instructionsPanel.demoInstructions.bulletPoints}}
- {{instructionsPanel.demoInstructions.bulletPoints}}

1. {{instructionsPanel.demoInstructions.numberedSteps}}
2. {{instructionsPanel.demoInstructions.numberedSteps}}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import demoInstructions from "../../../../assets/markdown/demoInstructions.md";
import RemoveInstructionsModal from "../../../Modals/RemoveInstructionsModal";
import Prism from "prismjs";
import "prismjs/components/prism-python";
import populateMarkdownTemplate from "../../../../utils/populateMarkdownTemplate";

const InstructionsPanel = () => {
const [showModal, setShowModal] = useState(false);
Expand Down Expand Up @@ -110,7 +111,11 @@ const InstructionsPanel = () => {
}, [quizCompleted, currentStepPosition, numberOfSteps, dispatch, isQuiz]);

const addInstructions = () => {
dispatch(setProjectInstructions(demoInstructions));
const translatedInstructions = populateMarkdownTemplate(
demoInstructions,
t,
);
dispatch(setProjectInstructions(translatedInstructions));
};

const removeInstructions = () => {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/populateMarkdownTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const populateMarkdownTemplate = (markdown, t) => {
return markdown.replace(/{{(.*?)}}/g, (_, key) => {
const translation = t(key);
return translation ? translation : `{{${key}}}`;
});
};

export default populateMarkdownTemplate;
25 changes: 25 additions & 0 deletions src/utils/populateMarkdownTemplate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import populateMarkdownTemplate from "./populateMarkdownTemplate";

describe("populatemarkdownTemplate", () => {
const t = (key) => {
const translations = {
name: "Alice",
place: "Wonderland",
};
return translations[key];
};

it("should replace placeholders with translations", () => {
const markdown = "Hello, {{name}}! Welcome to {{place}}.";

const result = populateMarkdownTemplate(markdown, t);
expect(result).toBe("Hello, Alice! Welcome to Wonderland.");
});

it("should leave placeholders unchanged if no translation is found", () => {
const markdown = "Hello, {{anotherName}}! Welcome to {{anotherPlace}}.";

const result = populateMarkdownTemplate(markdown, t);
expect(result).toBe("Hello, {{anotherName}}! Welcome to {{anotherPlace}}.");
});
});
Loading