Skip to content

Commit 0e6d39f

Browse files
refactor(SaveInterface): extract duplicated strings to constants
1 parent 69c9a1b commit 0e6d39f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

js/SaveInterface.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
* Class representing the SaveInterface.
2222
* @class
2323
*/
24+
const STR_MY_PROJECT = _("My Project");
25+
const STR_SHOW = _("Show");
26+
const STR_HIDE = _("Hide");
27+
2428
class SaveInterface {
2529
/**
2630
* Creates an instance of SaveInterface.
@@ -56,9 +60,9 @@ class SaveInterface {
5660
*/
5761
this.htmlSaveTemplate =
5862
'<!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") +
63+
STR_MY_PROJECT +
6064
' - {{ 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 {display: inline-block; margin-left: 10px; cursor: pointer; font-size: 14px; border-radius: 12px; border: 1px solid #1678ad; padding: 3px 5px; line-height: 20px; color: #181818;}.btn:hover {transition: 0.4s; -webkit-transition: 0.3s; -moz-transition: 0.3s; background-color: #3eb7e7;}.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") +
65+
STR_MY_PROJECT +
6266
' - {{ project_name }}</h3> <p>{{ project_description }}</p><hr> <div> <div style="color: #9E9E9E"><p>' +
6367
_("This project was created in Music Blocks") +
6468
' (<a href="https://musicblocks.sugarlabs.org" target="_blank">https://musicblocks.sugarlabs.org</a>). ' +
@@ -86,7 +90,7 @@ class SaveInterface {
8690
"</h4>" +
8791
_("This code stores data about the blocks in a project.") +
8892
'<a href="javascript:toggle();" id="showhide">' +
89-
_("Show") +
93+
STR_SHOW +
9094
"</a>" +
9195
'<button class="btn" onclick="copyCode()" style="margin-left: 10px;">' +
9296
_("Copy to Clipboard") +
@@ -99,12 +103,12 @@ class SaveInterface {
99103
' if (codeBlock.style.display === "none") {' +
100104
' codeBlock.style.display = "flex";' +
101105
' showHideButton.textContent = "' +
102-
_("Hide") +
106+
STR_HIDE +
103107
'";' +
104108
" } else {" +
105109
' codeBlock.style.display = "none";' +
106110
' showHideButton.textContent = "' +
107-
_("Show") +
111+
STR_SHOW +
108112
'";' +
109113
" }" +
110114
"}" +
@@ -113,7 +117,7 @@ class SaveInterface {
113117
' var showHideButton = document.getElementById("showhide");' +
114118
' codeBlock.style.display = "none";' +
115119
' showHideButton.textContent = "' +
116-
_("Show") +
120+
STR_SHOW +
117121
'";' +
118122
"};" +
119123
"function copyCode() {" +
@@ -161,7 +165,7 @@ class SaveInterface {
161165
let filename = null;
162166
if (defaultfilename === undefined || defaultfilename === null) {
163167
if (this.activity.PlanetInterface === undefined) {
164-
defaultfilename = _("My Project");
168+
defaultfilename = STR_MY_PROJECT;
165169
} else {
166170
defaultfilename = this.activity.PlanetInterface.getCurrentProjectName();
167171
}
@@ -233,7 +237,7 @@ class SaveInterface {
233237

234238
// let author = '';
235239
// Currently we're using anonymous for authors - not storing names.
236-
let name = _("My Project");
240+
let name = STR_MY_PROJECT;
237241
if (this.activity.PlanetInterface !== undefined) {
238242
name = this.activity.PlanetInterface.getCurrentProjectName();
239243
}
@@ -291,7 +295,7 @@ class SaveInterface {
291295
html
292296
);
293297
} else {
294-
activity.save.downloadURL(_("My Project").replace(" ", "_") + ".html", html);
298+
activity.save.downloadURL(STR_MY_PROJECT.replace(" ", "_") + ".html", html);
295299
}
296300
}, 500);
297301
}
@@ -585,7 +589,7 @@ class SaveInterface {
585589
}
586590

587591
const lyext = "ly";
588-
let filename = _("My Project");
592+
let filename = STR_MY_PROJECT;
589593
if (activity.PlanetInterface !== undefined) {
590594
filename = activity.PlanetInterface.getCurrentProjectName();
591595
}
@@ -613,7 +617,7 @@ class SaveInterface {
613617
docById("title").value = activity.PlanetInterface.getCurrentProjectName();
614618
} else {
615619
//.TRANS: default project title when saving as Lilypond
616-
docById("title").value = _("My Project");
620+
docById("title").value = STR_MY_PROJECT;
617621
}
618622

619623
// Load custom author saved in local storage.

0 commit comments

Comments
 (0)