Skip to content

Commit 5ead512

Browse files
committed
Migrate internationalization from webL10n to i18next in JS files
1 parent 1678672 commit 5ead512

File tree

161 files changed

+125900
-2726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+125900
-2726
lines changed

js/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ The color of the block is defined by the palette used.
169169
4. To designate a block for `beginnerMode`, add
170170
`this.beginnerBlock(true);` to the constructor.
171171

172-
5. To add a help string, add `this.setHelpString([_('some block
172+
5. To add a help string, add `this.setHelpString([t('some block
173173
help'), 'documentation', null, 'macroname']);` to the constructor. The
174174
first element in the list is the help string itself. The second
175175
element is the subdirectory where the help artwork is found. The third
@@ -259,7 +259,7 @@ An arg block:
259259
class TranspositionFactorBlock extends ValueBlock {
260260
constructor() {
261261
//.TRANS: musical transposition (adjustment of pitch up or down)
262-
super('transpositionfactor', _('transposition'));
262+
super('transpositionfactor', t('transposition'));
263263
this.setPalette('pitch');
264264
this.hidden = true;
265265
}
@@ -307,7 +307,7 @@ class StartDrumBlock extends StartBlock {
307307
super();
308308
this.changeName('startdrum');
309309
310-
this.formBlock({ name: _('start drum') });
310+
this.formBlock({ name: t('start drum') });
311311
312312
this.makeMacro((x, y) => [
313313
[0, 'start', x, y, [null, 1, null]],
@@ -331,9 +331,9 @@ class StartDrumBlock extends StartBlock {
331331
332332
//.TRANS: dispatch an event to trigger a listener
333333
this.formBlock({
334-
name: _('broadcast'),
334+
name: t('broadcast'),
335335
args: 1,
336-
defaults: [_('event')],
336+
defaults: [t('event')],
337337
argTypes: ['textin'],
338338
});
339339
}
@@ -362,7 +362,7 @@ class StartDrumBlock extends StartBlock {
362362
this.setPalette('graphics');
363363
364364
this.formBlock({
365-
name: this.lang === 'ja' ? _('x3') : _('x')
365+
name: this.lang === 'ja' ? t('x3') : t('x')
366366
});
367367
}
368368
@@ -391,7 +391,7 @@ class StartDrumBlock extends StartBlock {
391391

392392
`formBlock` is a method of `BaseBlock`. This function takes a JSON-like object describing the visual appearance of the block, its arguments etc. The format of that object is as follows:
393393

394-
1. `name` : This specifies the display name on the block. Typically it is of the format `_('...')`.
394+
1. `name` : This specifies the display name on the block. Typically it is of the format `t('...')`.
395395

396396
Note: If the `name` is omitted or is set to an empty string, a second argument of `false` should be passed to `formBlock` or else it will resize the block to fit the non-existent text.
397397

@@ -431,7 +431,7 @@ class MakeBlockBlock extends LeftBlock {
431431
432432
this.formBlock({
433433
//.TRANS: Create a new block programmatically.
434-
name: _('make block'),
434+
name: t('make block'),
435435
args: 1,
436436
argTypes: ['anyin'],
437437
outType: 'numberout',
@@ -440,7 +440,7 @@ class MakeBlockBlock extends LeftBlock {
440440
types: ['anyin'],
441441
labels: ['']
442442
},
443-
defaults: [_('note')]
443+
defaults: [t('note')]
444444
});
445445
}
446446
}
@@ -509,7 +509,7 @@ In order to set up a new synth effect:
509509
[rubrics.js](https://github.com/sugarlabs/musicblocks/blob/master/js/rubrics.js)
510510

511511
* As mentioned above, if you are adding user-facing strings, be sure
512-
to add them in this format: `_('string')` This allows the string to
512+
to add them in this format: `t('string')` This allows the string to
513513
be set up for translation into other languages.
514514

515515
* Before processing the notes, you need to check if the argument is present

js/SaveInterface.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,41 +56,41 @@ class SaveInterface {
5656
*/
5757
this.htmlSaveTemplate =
5858
'<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="{{ project_description }}"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <title>{{ project_name }}</title> <meta property="og:site_name" content="Music Blocks"/> <meta property="og:type" content="website"/> <meta property="og:title" content="' +
59-
_("Music Blocks Project") +
59+
t("Music Blocks Project") +
6060
' - {{ project_name }}"/> <meta property="og:description" content="{{ project_description }}"/> <style>body{background-color: #dbf0fb;}#main{background-color: white; padding: 5%; position: fixed; width: 80vw; height: max-content; margin: auto; top: 0; left: 0; bottom: 0; right: 0; display: flex; flex-direction: column; justify-content: center; text-align: center; color: #424242; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); font-family: "Roboto", "Helvetica","Arial",sans-serif;}h3{font-weight: 400; font-size: 36px; margin-top: 10px;}hr{border-top: 0px solid #ccc; margin: 1em;}.btn{border: solid; border-color: #96D3F3; padding: 5px 10px; line-height: 50px; color: #0a3e58;}.btn:hover{transition: 0.4s; -webkit-transition: 0.3s; -moz-transition: 0.3s; background-color: #96D3F3;}.code{word-break: break-all; height: 15vh; background: #f6f8fa; color: #494949; text-align: justify; margin-right: 10vw; margin-left: 10vw; padding: 16px; overflow: auto; line-height: 1.45; background-color: #f6f8fa; border-radius: 3px; font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;}.image{border-radius: 2px 2px 0 0; position: relative; background-color: #96D3F3;}.image-div{margin-bottom: 10px;}.moreinfo-div{margin-top: 20px;}h4{font-weight: 500; font-size: 1.4em; margin-top: 10px; margin-bottom: 10px;}.tbcode{margin-bottom: 10px;}</style></head><body> <div id="main"> <div class="image-div"><img class="image" id="project-image" src="{{ project_image }}"></div><h3 id="title">' +
61-
_("Music Blocks Project") +
61+
t("Music Blocks Project") +
6262
' - {{ project_name }}</h3> <p>{{ project_description }}</p><hr> <div> <div style="color: #9E9E9E"><p>' +
63-
_("This project was created in Music Blocks") +
63+
t("This project was created in Music Blocks") +
6464
' (<a href="https://musicblocks.sugarlabs.org" target="_blank">https://musicblocks.sugarlabs.org</a>). ' +
6565
TITLESTRING +
6666
" " +
67-
_("Music Blocks is a Free/Libre Software application.") +
67+
t("Music Blocks is a Free/Libre Software application.") +
6868
" " +
69-
_("The source code can be accessed at") +
69+
t("The source code can be accessed at") +
7070
' <a href="https://github.com/sugarlabs/musicblocks" target="_blank">https://github.com/sugarlabs/musicblocks</a>.' +
7171
" " +
72-
_("For more information, please consult the") +
72+
t("For more information, please consult the") +
7373
' <a href="' +
7474
GUIDEURL +
7575
'" target="_blank">' +
76-
_("Music Blocks Guide") +
76+
t("Music Blocks Guide") +
7777
"</a>." +
7878
"</p><p>" +
79-
_(
79+
t(
8080
"To run this project, open Music Blocks in a web browser and drag and drop this file into the browser window."
8181
) +
8282
" " +
83-
_("Alternatively, open the file in Music Blocks using the Load project button.") +
83+
t("Alternatively, open the file in Music Blocks using the Load project button.") +
8484
'</p></div><div class="moreinfo-div"> <div class="tbcode"><h4>' +
85-
_("Project Code") +
85+
t("Project Code") +
8686
"</h4>" +
87-
_("This code stores data about the blocks in a project.") +
87+
t("This code stores data about the blocks in a project.") +
8888
' <a href="javascript:toggle();" id="showhide">' +
89-
_("Show") +
89+
t("Show") +
9090
'</a></div> <div class="code">{{ data }}</div></div></div></div><script type="text/javascript">function toggle(){if (document.getElementsByClassName("code")[0].style.display=="none"){document.getElementsByClassName("code")[0].style.display="flex";document.getElementById("showhide").textContent = "' +
91-
_("Hide") +
91+
t("Hide") +
9292
'";} else {document.getElementsByClassName("code")[0].style.display="none";document.getElementById("showhide").textContent = "Show";}} var name=decodeURIComponent(window.location.pathname.split("/").pop().slice(0, -5)); var prefix="' +
93-
_("Music Blocks Project") +
93+
t("Music Blocks Project") +
9494
' - "; var title=prefix+name; document.querySelector(' +
9595
"'" +
9696
'meta[property="og:title"]' +
@@ -128,7 +128,7 @@ class SaveInterface {
128128
let filename = null;
129129
if (defaultfilename === undefined || defaultfilename === null) {
130130
if (this.activity.PlanetInterface === undefined) {
131-
defaultfilename = _("My Project");
131+
defaultfilename = t("My Project");
132132
} else {
133133
defaultfilename = this.activity.PlanetInterface.getCurrentProjectName();
134134
}
@@ -194,14 +194,14 @@ class SaveInterface {
194194
*/
195195
prepareHTML() {
196196
let file = this.htmlSaveTemplate;
197-
let description = _("No description provided");
197+
let description = t("No description provided");
198198
if (this.activity.PlanetInterface !== undefined) {
199199
description = this.activity.PlanetInterface.getCurrentProjectDescription();
200200
}
201201

202202
// let author = '';
203203
// Currently we're using anonymous for authors - not storing names.
204-
let name = _("My Project");
204+
let name = t("My Project");
205205
if (this.activity.PlanetInterface !== undefined) {
206206
name = this.activity.PlanetInterface.getCurrentProjectName();
207207
}
@@ -259,7 +259,7 @@ class SaveInterface {
259259
html
260260
);
261261
} else {
262-
activity.save.downloadURL(_("My Project").replace(" ", "_") + ".html", html);
262+
activity.save.downloadURL(t("My Project").replace(" ", "_") + ".html", html);
263263
}
264264
}, 500);
265265
}
@@ -455,7 +455,7 @@ class SaveInterface {
455455
activity.logo.synth.setupRecorder();
456456
activity.logo.synth.recorder.start();
457457
activity.logo.runLogoCommands();
458-
activity.textMsg(_("Your recording is in progress."));
458+
activity.textMsg(t("Your recording is in progress."));
459459
}
460460

461461
/**
@@ -512,7 +512,7 @@ class SaveInterface {
512512
*/
513513
saveLilypond(activity) {
514514
const lyext = "ly";
515-
let filename = _("My Project");
515+
let filename = t("My Project");
516516
if (activity.PlanetInterface !== undefined) {
517517
filename = activity.PlanetInterface.getCurrentProjectName();
518518
}
@@ -524,23 +524,23 @@ class SaveInterface {
524524
docById("lilypondModal").style.display = "block";
525525

526526
//.TRANS: File name prompt for save as Lilypond
527-
docById("fileNameText").textContent = _("File name");
527+
docById("fileNameText").textContent = t("File name");
528528
//.TRANS: Project title prompt for save as Lilypond
529-
docById("titleText").textContent = _("Project title");
529+
docById("titleText").textContent = t("Project title");
530530
//.TRANS: Project title prompt for save as Lilypond
531-
docById("authorText").textContent = _("Project author");
531+
docById("authorText").textContent = t("Project author");
532532
//.TRANS: MIDI prompt for save as Lilypond
533-
docById("MIDIText").textContent = _("Include MIDI output?");
533+
docById("MIDIText").textContent = t("Include MIDI output?");
534534
//.TRANS: Guitar prompt for save as Lilypond
535-
docById("guitarText").textContent = _("Include guitar tablature output?");
535+
docById("guitarText").textContent = t("Include guitar tablature output?");
536536
//.TRANS: Lilypond is a scripting language for generating sheet music
537-
docById("submitLilypond").textContent = _("Save as Lilypond");
537+
docById("submitLilypond").textContent = t("Save as Lilypond");
538538
docById("fileName").value = filename;
539539
if (activity.PlanetInterface !== undefined) {
540540
docById("title").value = activity.PlanetInterface.getCurrentProjectName();
541541
} else {
542542
//.TRANS: default project title when saving as Lilypond
543-
docById("title").value = _("My Project");
543+
docById("title").value = t("My Project");
544544
}
545545

546546
// Load custom author saved in local storage.
@@ -549,7 +549,7 @@ class SaveInterface {
549549
docById("author").value = JSON.parse(customAuthorData);
550550
} else {
551551
//.TRANS: default project author when saving as Lilypond
552-
docById("author").value = _("Mr. Mouse");
552+
docById("author").value = t("Mr. Mouse");
553553
}
554554

555555
docById("submitLilypond").onclick = () => {
@@ -698,7 +698,7 @@ class SaveInterface {
698698
document.execCommand("copy");
699699
tmp.remove();
700700
this.activity.textMsg(
701-
_("The Lilypond code is copied to clipboard. You can paste it here: ") +
701+
t("The Lilypond code is copied to clipboard. You can paste it here: ") +
702702
"<a href='http://hacklily.org' target='_blank'>http://hacklily.org</a> "
703703
);
704704
}

js/__tests__/turtle-singer.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ describe('Singer Class', () => {
5959
// Add blockList here
6060
blockList: {
6161
mockBlk: {
62+
<<<<<<< HEAD
6263
connections: [0, 0]
64+
=======
65+
connections: ['mockConnection1', 'mockConnection2']
66+
>>>>>>> f399f6ac (Update VolumeActions.test.js)
6367
}
6468
}
6569
},
@@ -108,7 +112,11 @@ describe('Singer Class', () => {
108112

109113
test('should set master volume correctly', () => {
110114
Singer.setMasterVolume(logoMock, 50, 'mockBlk');
115+
<<<<<<< HEAD
111116
expect(logoMock.synth.setMasterVolume).toHaveBeenCalledWith(50, 0, 0);
117+
=======
118+
expect(logoMock.synth.setMasterVolume).toHaveBeenCalledWith(50, 'mockConnection1', 'mockConnection2');
119+
>>>>>>> f399f6ac (Update VolumeActions.test.js)
112120
});
113121

114122
test('should set synth volume correctly', () => {

0 commit comments

Comments
 (0)