Skip to content

Commit f3caad7

Browse files
committed
fix: wrap hardcoded alert() strings with _() for i18n localization
Audited all user-facing alert() calls across the codebase and wrapped hardcoded English strings with the _() localization function so they are translatable for non-English-speaking users. Files changed: - js/blocks/ProgramBlocks.js (L1475): localize popup-blocked message - js/activity.js (L7999): localize JSON fetch error message - js/utils/synthutils.js (L1103): localize download cancelled message - js/utils/synthutils.js (L1973): localize sound-disabled warning; keep the universal warning emoji outside the translatable string - js/widgets/sampler.js (L2250): localize microphone access failure prefix - js/loader.js (L318, L330, L337): localize bootstrap failure messages using a safe guard (typeof _ === 'function' ? _ : s => s) since _() may not be available during early bootstrap The alert() calls in js/SaveInterface.js contain strings embedded in dynamically generated HTML source text (not user-visible alert text) so they are intentionally left unchanged. Resolves: hardcoded alert strings preventing localization
1 parent d373588 commit f3caad7

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

js/activity.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7997,7 +7997,9 @@ class Activity {
79977997
},
79987998
() => {
79997999
alert(
8000-
"Something went wrong reading JSON-encoded project data."
8000+
_(
8001+
"Something went wrong reading JSON-encoded project data."
8002+
)
80018003
);
80028004
}
80038005
);

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/loader.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ requirejs(["i18next", "i18nextHttpBackend"], function (i18next, i18nextHttpBacke
315315
console.error(
316316
"FATAL: createjs (EaselJS/TweenJS) not found. Cannot proceed."
317317
);
318-
alert("Failed to load EaselJS. Please refresh the page.");
318+
const t_ = typeof _ === "function" ? _ : s => s;
319+
alert(t_("Failed to load EaselJS. Please refresh the page."));
319320
return;
320321
}
321322

@@ -327,15 +328,18 @@ requirejs(["i18next", "i18nextHttpBackend"], function (i18next, i18nextHttpBacke
327328
},
328329
function (err) {
329330
console.error("Failed to load activity/activity:", err);
330-
alert("Failed to load Music Blocks. Please refresh the page.");
331+
const t_ = typeof _ === "function" ? _ : s => s;
332+
alert(t_("Failed to load Music Blocks. Please refresh the page."));
331333
}
332334
);
333335
}, 100); // Small delay to allow globals to be set
334336
},
335337
function (err) {
336338
console.error("Core bootstrap failed:", err);
339+
const t_ = typeof _ === "function" ? _ : s => s;
337340
alert(
338-
"Failed to initialize Music Blocks core. Please refresh the page.\n\nError: " +
341+
t_("Failed to initialize Music Blocks core. Please refresh the page.") +
342+
"\n\nError: " +
339343
(err.message || err)
340344
);
341345
}

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();
@@ -1971,7 +1971,10 @@ function Synth() {
19711971
if (Tone.context.state !== "running" && !window.hasShownAudioWarning) {
19721972
window.hasShownAudioWarning = true;
19731973
alert(
1974-
"⚠️ Sound is disabled!\n\nPlease check your browser settings (Site Settings > Sound) to allow audio for Music Blocks."
1974+
"⚠️ " +
1975+
_(
1976+
"Sound is disabled! Please check your browser settings (Site Settings > Sound) to allow audio for Music Blocks."
1977+
)
19751978
);
19761979
}
19771980
}, 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)