Skip to content

Commit 8f71279

Browse files
committed
fix: localize hardcoded alert() strings and fix GraphicsBlocks tests
1 parent 120e37e commit 8f71279

File tree

6 files changed

+53
-52
lines changed

6 files changed

+53
-52
lines changed

js/activity.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7958,7 +7958,9 @@ class Activity {
79587958
},
79597959
() => {
79607960
alert(
7961-
"Something went wrong reading JSON-encoded project data."
7961+
_(
7962+
"Something went wrong reading JSON-encoded project data."
7963+
)
79627964
);
79637965
}
79647966
);

js/blocks/ProgramBlocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ function setupProgramBlocks(activity) {
14721472
win.focus();
14731473
} else {
14741474
// Browser has blocked it.
1475-
alert("Please allow popups for this site");
1475+
alert(_("Please allow popups for this site"));
14761476
}
14771477
}
14781478
}

js/blocks/__tests__/GraphicsBlocks.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ describe("GraphicsBlocks", () => {
8080
};
8181

8282
activity = {
83-
blocks: {},
83+
blocks: {
84+
blockList: {}
85+
},
8486
errorMsg: jest.fn(),
8587
turtles: {
8688
companionTurtle: jest.fn(() => 0),

js/loader.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ requirejs(["i18next", "i18nextHttpBackend"], function (i18next, i18nextHttpBacke
321321
console.error(
322322
"FATAL: createjs (EaselJS/TweenJS) not found. Cannot proceed."
323323
);
324-
alert("Failed to load EaselJS. Please refresh the page.");
324+
const t_ = typeof _ === "function" ? _ : s => s;
325+
alert(t_("Failed to load EaselJS. Please refresh the page."));
325326
return;
326327
}
327328

@@ -333,15 +334,18 @@ requirejs(["i18next", "i18nextHttpBackend"], function (i18next, i18nextHttpBacke
333334
},
334335
function (err) {
335336
console.error("Failed to load activity/activity:", err);
336-
alert("Failed to load Music Blocks. Please refresh the page.");
337+
const t_ = typeof _ === "function" ? _ : s => s;
338+
alert(t_("Failed to load Music Blocks. Please refresh the page."));
337339
}
338340
);
339341
}, 100); // Small delay to allow globals to be set
340342
},
341343
function (err) {
342344
console.error("Core bootstrap failed:", err);
345+
const t_ = typeof _ === "function" ? _ : s => s;
343346
alert(
344-
"Failed to initialize Music Blocks core. Please refresh the page.\n\nError: " +
347+
t_("Failed to initialize Music Blocks core. Please refresh the page.") +
348+
"\n\nError: " +
345349
(err.message || err)
346350
);
347351
}

js/utils/synthutils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ function Synth() {
11001100
if (fileName) {
11011101
download(url, fileName + (platform.FF ? ".wav" : ".ogg"));
11021102
} else {
1103-
alert("Download cancelled.");
1103+
alert(_("Download cancelled."));
11041104
}
11051105
};
11061106
// this.recorder.start();
@@ -1992,7 +1992,10 @@ function Synth() {
19921992
if (Tone.context.state !== "running" && !window.hasShownAudioWarning) {
19931993
window.hasShownAudioWarning = true;
19941994
alert(
1995-
"⚠️ Sound is disabled!\n\nPlease check your browser settings (Site Settings > Sound) to allow audio for Music Blocks."
1995+
"⚠️ " +
1996+
_(
1997+
"Sound is disabled! Please check your browser settings (Site Settings > Sound) to allow audio for Music Blocks."
1998+
)
19961999
);
19972000
}
19982001
}, 2000);

js/widgets/sampler.js

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ function SampleWidget() {
189189
this.activity.blocks.blockList[mainSampleBlock].text.text
190190
) {
191191
// Append cent adjustment to the block text if possible
192-
const currentText = this.activity.blocks.blockList[mainSampleBlock].text
193-
.text;
192+
const currentText =
193+
this.activity.blocks.blockList[mainSampleBlock].text.text;
194194
if (!currentText.includes("¢")) {
195195
this.activity.blocks.blockList[mainSampleBlock].text.text +=
196196
" " + centText;
@@ -522,29 +522,25 @@ function SampleWidget() {
522522
}
523523
};
524524

525-
widgetWindow.addButton(
526-
"load-media.svg",
527-
ICONSIZE,
528-
_("Upload sample"),
529-
""
530-
).onclick = function () {
531-
stopTuner();
532-
const fileChooser = docById("myOpenAll");
525+
widgetWindow.addButton("load-media.svg", ICONSIZE, _("Upload sample"), "").onclick =
526+
function () {
527+
stopTuner();
528+
const fileChooser = docById("myOpenAll");
529+
530+
// eslint-disable-next-line no-unused-vars
531+
const __readerAction = function (event) {
532+
window.scroll(0, 0);
533+
const sampleFile = fileChooser.files[0];
534+
that.handleFiles(sampleFile);
535+
fileChooser.removeEventListener("change", __readerAction);
536+
};
533537

534-
// eslint-disable-next-line no-unused-vars
535-
const __readerAction = function (event) {
538+
fileChooser.addEventListener("change", __readerAction, false);
539+
fileChooser.focus();
540+
fileChooser.click();
536541
window.scroll(0, 0);
537-
const sampleFile = fileChooser.files[0];
538-
that.handleFiles(sampleFile);
539-
fileChooser.removeEventListener("change", __readerAction);
540542
};
541543

542-
fileChooser.addEventListener("change", __readerAction, false);
543-
fileChooser.focus();
544-
fileChooser.click();
545-
window.scroll(0, 0);
546-
};
547-
548544
// Create a container for the pitch button and frequency display
549545
this.pitchBtnContainer = document.createElement("div");
550546
this.pitchBtnContainer.className = "wfbtItem";
@@ -576,22 +572,18 @@ function SampleWidget() {
576572
};
577573

578574
this._save_lock = false;
579-
widgetWindow.addButton(
580-
"export-chunk.svg",
581-
ICONSIZE,
582-
_("Save sample"),
583-
""
584-
).onclick = function () {
585-
stopTuner();
586-
// Debounce button
587-
if (!that._get_save_lock()) {
588-
that._save_lock = true;
589-
that._saveSample();
590-
setTimeout(function () {
591-
that._save_lock = false;
592-
}, 1000);
593-
}
594-
};
575+
widgetWindow.addButton("export-chunk.svg", ICONSIZE, _("Save sample"), "").onclick =
576+
function () {
577+
stopTuner();
578+
// Debounce button
579+
if (!that._get_save_lock()) {
580+
that._save_lock = true;
581+
that._saveSample();
582+
setTimeout(function () {
583+
that._save_lock = false;
584+
}, 1000);
585+
}
586+
};
595587

596588
this._recordBtn = widgetWindow.addButton("mic.svg", ICONSIZE, _("Toggle Mic"), "");
597589

@@ -1783,9 +1775,8 @@ function SampleWidget() {
17831775

17841776
const __selectionChanged = () => {
17851777
const label = this._pitchWheel.navItems[this._pitchWheel.selectedNavItemIndex].title;
1786-
const attr = this._accidentalsWheel.navItems[
1787-
this._accidentalsWheel.selectedNavItemIndex
1788-
].title;
1778+
const attr =
1779+
this._accidentalsWheel.navItems[this._accidentalsWheel.selectedNavItemIndex].title;
17891780
const octave = Number(
17901781
this._octavesWheel.navItems[this._octavesWheel.selectedNavItemIndex].title
17911782
);
@@ -2047,9 +2038,8 @@ function SampleWidget() {
20472038
const playbackRate = TunerUtils.calculatePlaybackRate(0, this.centsValue);
20482039
// Apply the playback rate to the sample
20492040
if (instruments[0]["customsample_" + this.originalSampleName]) {
2050-
instruments[0][
2051-
"customsample_" + this.originalSampleName
2052-
].playbackRate.value = playbackRate;
2041+
instruments[0]["customsample_" + this.originalSampleName].playbackRate.value =
2042+
playbackRate;
20532043
}
20542044
}
20552045
};
@@ -2247,7 +2237,7 @@ function SampleWidget() {
22472237
this.pitchDetectionAnimationId = requestAnimationFrame(updatePitch);
22482238
} catch (err) {
22492239
console.error(`${err.name}: ${err.message}`);
2250-
alert("Microphone access failed: " + err.message);
2240+
alert(_("Microphone access failed: ") + err.message);
22512241
// Clean up any partially initialized resources
22522242
this.stopPitchDetection();
22532243
}

0 commit comments

Comments
 (0)