forked from catchspider2002/periodic-table.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlTranslation.js
440 lines (375 loc) · 19.5 KB
/
htmlTranslation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
const fs = require("fs");
const dotenv = require("dotenv");
const onesky = require("@brainly/onesky-utils");
dotenv.config();
function returnItem(code) {
for (let j = 0; j < languageList.length; j++) {
if (languageList[j].code === code) return languageList[j].id;
}
}
let languageList = [
{ id: 1, code: "en" },
{ id: 45, code: "en-GB" },
{ id: 576, code: "bg" },
{ id: 23, code: "ca" },
{ id: 3, code: "zh-CN" },
{ id: 2, code: "zh-TW" },
{ id: 22, code: "hr" },
{ id: 13, code: "cs" },
{ id: 27, code: "da" },
{ id: 12, code: "nl" },
{ id: 18, code: "fi" },
{ id: 5, code: "fr" },
{ id: 6, code: "de" },
{ id: 20, code: "el" },
{ id: 587, code: "hi" },
{ id: 21, code: "hu" },
{ id: 62, code: "hy" },
{ id: 54, code: "id" },
{ id: 10, code: "it" },
{ id: 4, code: "ja" },
{ id: 9, code: "ko" },
{ id: 55, code: "ms" },
{ id: 77, code: "nb" },
{ id: 15, code: "nn" },
{ id: 16, code: "pl" },
{ id: 563, code: "pt" },
{ id: 19, code: "ro" },
{ id: 11, code: "ru" },
{ id: 462, code: "sr" },
{ id: 34, code: "sk" },
{ id: 659, code: "sl" },
{ id: 79, code: "es" },
{ id: 17, code: "sv" },
{ id: 56, code: "th" },
{ id: 14, code: "tr" },
{ id: 36, code: "uk" },
{ id: 50, code: "vi" },
{ id: 28, code: "ar" },
{ id: 42, code: "he" },
{ id: 29, code: "fa" },
{ id: 159, code: "kk" },
{ id: 213, code: "uz" },
{ id: 24, code: "eo" },
{ id: 249, code: "az" },
{ id: 31, code: "fil" },
{ id: 38, code: "lv-LV" },
{ id: 43, code: "is-IS" },
{ id: 494, code: "sw" },
{ id: 55, code: "ms" },
{ id: 60, code: "af" },
{ id: 624, code: "et" },
{ id: 63, code: "sq" },
{ id: 641, code: "lt" },
{ id: 644, code: "mk" },
{ id: 66, code: "be-BY" },
{ id: 505, code: "ta" },
{ id: 662, code: "te" },
];
let unavailable = [
"Albanian",
"Azerbaijani",
"Belarusian",
"Estonian",
"Filipino",
"Icelandic",
"Kazakh",
"Latvian",
"Lithuanian",
"Swahili",
"Telugu",
];
let color;
let today = new Date();
let date = today.toLocaleString("default", { month: "long" }) + " " + today.getDate() + ", " + today.getFullYear();
const writeFile = (lang, langValues, page, defaultHead, metaTags, defaultNav, nav4, defaultFooter) => {
let available1Markup = "";
let unavailable1Markup = "";
let unavailable1HTML = "";
let available1HTML = "";
let available2Markup = "";
let unavailable2Markup = "";
let unavailable2HTML = "";
let available2HTML = "";
let project_id = 190138;
let options = {
secret: process.env.ONESKY_SECRET,
apiKey: process.env.ONESKY_APIKEY,
projectId: project_id,
};
onesky
.getLanguages(options)
.then(function (content) {
let result = JSON.parse(content);
let mappedResult = result.data
.map((language) => {
return {
english_name: language.english_name
.replace(" (Latvia)", "")
.replace(" (Belarus)", "")
.replace(" (Iceland)", "")
.replace(" / Tagalog", ""),
translation_progress: parseFloat(language.translation_progress.replace("%", "")),
code: returnItem(language.code),
};
})
.filter((lang) => {
return lang.english_name !== "English" && lang.english_name !== "English (United Kingdom)";
})
.sort(function (x, y) {
let a = x.english_name.toUpperCase(),
b = y.english_name.toUpperCase();
return a == b ? 0 : a > b ? 1 : -1;
});
mappedResult.forEach(function (item) {
let percent = item.translation_progress;
let englishName = item.english_name;
if (percent === 100) color = "brightgreen";
else if (percent > 80) color = "green";
else if (percent > 65) color = "yellow";
else if (percent > 50) color = "orange";
else color = "red";
let newName = englishName.replace(/ /g, "%20");
let newLink = "https://windows-uwp.oneskyapp.com/collaboration/translate/project/project/" + project_id + "/language/" + item.code;
let badgeLink = "https://img.shields.io/badge/" + newName + "-" + percent + "%25-" + color;
if (unavailable.indexOf(englishName) > -1) {
unavailable1Markup = unavailable1Markup + "[![" + newName + "](" + badgeLink + ")](" + newLink + ")\n";
// unavailable1HTML = unavailable1HTML + "<a target='_blank' href='" + newLink + "'><img src='" + badgeLink + "' alt='" + newName + "'></a>";
unavailable1HTML =
unavailable1HTML +
`<a class='langOuter' target='_blank' href='${newLink}'><span>${englishName}</span><span class='${color}'>${percent}%</span></a>`;
} else {
available1Markup = available1Markup + "[![" + newName + "](" + badgeLink + ")](" + newLink + ")\n";
// unavailable1HTML = unavailable1HTML + "<a target='_blank' href='" + newLink + "'><img src='" + badgeLink + "' alt='" + newName + "'></a>";
available1HTML =
available1HTML +
`<a class='langOuter' target='_blank' href='${newLink}'><span>${englishName}</span><span class='${color}'>${percent}%</span></a>`;
}
});
})
.then(function () {
project_id = 197066;
options = {
secret: process.env.ONESKY_SECRET,
apiKey: process.env.ONESKY_APIKEY,
projectId: project_id,
};
onesky
.getLanguages(options)
.then(function (content) {
let result = JSON.parse(content);
let mappedResult = result.data
.map((language) => {
return {
english_name: language.english_name
.replace(" (Latvia)", "")
.replace(" (Belarus)", "")
.replace(" (Iceland)", "")
.replace(" / Tagalog", ""),
translation_progress: parseFloat(language.translation_progress.replace("%", "")),
code: returnItem(language.code),
};
})
.filter((lang) => {
return lang.english_name !== "English" && lang.english_name !== "English (United Kingdom)";
})
.sort(function (x, y) {
let a = x.english_name.toUpperCase(),
b = y.english_name.toUpperCase();
return a == b ? 0 : a > b ? 1 : -1;
});
mappedResult.forEach(function (item) {
let percent = item.translation_progress;
let englishName = item.english_name;
if (percent === 100) color = "brightgreen";
else if (percent > 80) color = "green";
else if (percent > 65) color = "yellow";
else if (percent > 50) color = "orange";
else color = "red";
let newName = englishName.replace(/ /g, "%20");
let newLink = "https://windows-uwp.oneskyapp.com/collaboration/translate/project/project/" + project_id + "/language/" + item.code;
let badgeLink = "https://img.shields.io/badge/" + newName + "-" + percent + "%25-" + color;
if (unavailable.indexOf(englishName) > -1) {
unavailable2Markup = unavailable2Markup + "[![" + newName + "](" + badgeLink + ")](" + newLink + ")\n";
// unavailable2HTML = unavailable2HTML + "<a target='_blank' href='" + newLink + "'><img src='" + badgeLink + "' alt='" + newName + "'></a>";
unavailable2HTML =
unavailable2HTML +
`<a class='langOuter' target='_blank' href='${newLink}'><span>${englishName}</span><span class='${color}'>${percent}%</span></a>`;
} else {
available2Markup = available2Markup + "[![" + newName + "](" + badgeLink + ")](" + newLink + ")\n";
// available2HTML = available2HTML + "<a target='_blank' href='" + newLink + "'><img src='" + badgeLink + "' alt='" + newName + "'></a>";
available2HTML =
available2HTML +
`<a class='langOuter' target='_blank' href='${newLink}'><span>${englishName}</span><span class='${color}'>${percent}%</span></a>`;
}
});
})
.then(function () {
let writeStream = fs.createWriteStream(lang + "/" + page + ".html");
defaultHead.forEach((heads) => {
writeStream.write(heads);
});
metaTags.forEach((tags) => {
writeStream.write(tags);
});
defaultNav.forEach((navs) => {
writeStream.write(navs);
});
writeStream.write("<h1 class='truncate'>" + langValues.translation + "</h1>");
nav4.forEach((navs) => {
writeStream.write(navs);
});
writeStream.write("<div class='content-wrapper'>");
writeStream.write("<div class='container'>");
writeStream.write("<div id='translationHeader' class='row text-upper aboutHeader text-center heavyFont'></div>");
writeStream.write("<div id='translationContent'>");
writeStream.write("<h1>Translations (As of " + date + ")</h1>");
writeStream.write(
"<p>Contributions are welcome for the translations. <strong>Click on the translation status badge below to go directly to that language translation page.</strong> There are 2 files available for translation: General Terms and Element Details.</p>"
);
writeStream.write("<h2>General Terms</h2>");
writeStream.write(
"<p>This contains the text for the labels used in all the pages except for the element details mentioned below. The current status of the translation is below:</p>"
);
writeStream.write("<h4>Available in the website</h4>");
writeStream.write("<p>");
writeStream.write(available1HTML);
writeStream.write("</p>");
writeStream.write("<h4>Below are not yet added to the website. I'll be adding new languages when it is crosses 70% translation.</h4>");
writeStream.write("<p>");
writeStream.write(unavailable1HTML);
writeStream.write("</p>");
writeStream.write("<h2>Element Details</h2>");
writeStream.write(
"<p>This contains the text for individual element details like name reason, history, facts, applications and hazards. Below is a sample from Hydrogen element:</p>"
);
writeStream.write("<p><strong>Name Reason</strong></p>");
writeStream.write("<blockquote>");
writeStream.write("<p>From the Greek word <em>hydro</em> (water), and <em>genes</em> (forming)</p>");
writeStream.write("</blockquote>");
writeStream.write("<p><strong>History</strong></p>");
writeStream.write("<blockquote>");
writeStream.write(
"<p>Henry Cavendish was the first to distinguish hydrogen from other gases in 1766 when he prepared it by reacting hydrochloric acid with zinc.<br><br>In 1670, English scientist Robert Boyle had observed its production by reacting strong acids with metals.<br><br>French scientist Antoine Lavoisier later named the element hydrogen in 1783.</p>"
);
writeStream.write("</blockquote>");
writeStream.write("<p><strong>Facts</strong></p>");
writeStream.write("<blockquote>");
writeStream.write("<p>Hydrogen is the primary component of Jupiter and the other gas giant planets</p>");
writeStream.write("</blockquote>");
writeStream.write("<p><strong>Applications</strong></p>");
writeStream.write("<blockquote>");
writeStream.write(
"<p>Liquid hydrogen is used as a rocket fuel.<br><br>Hydrogen is commonly used in power stations as a coolant in generators.<br><br>Hydrogen's two heavier isotopes (deuterium and tritium) are used in nuclear fusion. Used as a shielding gas in welding methods such as atomic hydrogen welding.</p>"
);
writeStream.write("</blockquote>");
writeStream.write("<p><strong>Hazards</strong></p>");
writeStream.write("<blockquote>");
writeStream.write(
"<p>Hydrogen poses a number of hazards to safety, from fires when mixed with air to being an asphyxiant in its pure form</p>"
);
writeStream.write("</blockquote>");
writeStream.write("<h4>Available in the website</h4>");
writeStream.write("<p>");
writeStream.write(available2HTML);
writeStream.write("</p>");
writeStream.write("<h4>Below are not yet added to the website since the General Terms is not 70% translated</h4>");
writeStream.write("<p>");
writeStream.write(unavailable2HTML);
writeStream.write("</p>");
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("</div>");
defaultFooter.forEach((footers) => {
writeStream.write(footers);
});
// the finish event is emitted when all data has been flushed from the stream
writeStream.on("finish", () => {
console.log("Created " + lang + "-" + page);
});
// close the stream
writeStream.end();
})
.then(function () {
let readmeStream = fs.createWriteStream("README.md");
readmeStream.write("# periodic-table.io\n\n");
readmeStream.write("![GitHub repo size](https://img.shields.io/github/repo-size/catchspider2002/periodic-table.io)\n");
readmeStream.write("[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n");
readmeStream.write("![GitHub last commit](https://img.shields.io/github/last-commit/catchspider2002/periodic-table.io)\n");
readmeStream.write("![Website](https://img.shields.io/website?up_message=online&url=https%3A%2F%2Fperiodic-table.io%2F)\n\n");
readmeStream.write("<div align='center'>\n");
readmeStream.write("<img src='images2/icons/android-chrome-192x192.png' alt='periodic-table.io' />\n");
readmeStream.write("</div>\n\n");
readmeStream.write(
"[periodic-table.io](https://periodic-table.io) provides comprehensive and useful information about the chemical elements all in one place. Click on an element to know more about the properties, history, name origin, images, applications, hazards and electron shell diagram of each element.\n\n"
);
readmeStream.write("- Visually pleasing colour coded table\n");
readmeStream.write("- Simple fluid design and has lots of details\n");
readmeStream.write("- Detailed description for each element\n");
readmeStream.write("- View the list of all elements in the alphabetical order\n");
readmeStream.write("- Electron shell diagram and image for each element\n");
readmeStream.write("- Compare the properties of 2 elements\n");
readmeStream.write("- Search for the elements using their symbol, atomic number or name\n");
readmeStream.write("- Links to informative websites for further study\n\n");
readmeStream.write("# Translations (As of " + date + ")\n\n");
readmeStream.write(
"Contributions are welcome for the translations. **Click on the translation status badge below to go directly to that language translation page.** There are 2 files available for translation: General Terms and Element Details.\n\n"
);
readmeStream.write("## General Terms\n");
readmeStream.write(
"This contains the text for the labels used in all the pages except for the element details mentioned below. The current status of the translation is below:\n\n"
);
readmeStream.write("#### Available in the website\n\n");
readmeStream.write(available1Markup);
readmeStream.write("\n");
readmeStream.write("#### Below are not yet added to the website. I'll be adding new languages when it is crosses 70% translation.\n\n");
readmeStream.write(unavailable1Markup);
readmeStream.write("\n");
readmeStream.write("## Element Details\n");
readmeStream.write(
"This contains the text for individual element details like name reason, history, facts, applications and hazards. Below is a sample from Hydrogen element:\n\n"
);
readmeStream.write("**Name Reason**\n");
readmeStream.write("> From the Greek word *hydro* (water), and *genes* (forming)\n\n");
readmeStream.write("**History**\n");
readmeStream.write(
"> Henry Cavendish was the first to distinguish hydrogen from other gases in 1766 when he prepared it by reacting hydrochloric acid with zinc.<br><br>In 1670, English scientist Robert Boyle had observed its production by reacting strong acids with metals.<br><br>French scientist Antoine Lavoisier later named the element hydrogen in 1783.\n\n"
);
readmeStream.write("**Facts**\n");
readmeStream.write("> Hydrogen is the primary component of Jupiter and the other gas giant planets\n\n");
readmeStream.write("**Applications**\n");
readmeStream.write(
"> Liquid hydrogen is used as a rocket fuel.<br><br>Hydrogen is commonly used in power stations as a coolant in generators.<br><br>Hydrogen's two heavier isotopes (deuterium and tritium) are used in nuclear fusion. Used as a shielding gas in welding methods such as atomic hydrogen welding.\n\n"
);
readmeStream.write("**Hazards**\n");
readmeStream.write(
"> Hydrogen poses a number of hazards to safety, from fires when mixed with air to being an asphyxiant in its pure form\n\n"
);
readmeStream.write("#### Available in the website\n\n");
readmeStream.write(available2Markup);
readmeStream.write("\n");
readmeStream.write("#### Below are not yet added to the website since the General Terms is not 70% translated\n\n");
readmeStream.write(unavailable2Markup);
readmeStream.write("\n\n");
readmeStream.write("# License\n\n");
readmeStream.write("MIT License\n\n");
readmeStream.write("Copyright (c) 2018-2021 periodic-table.io\n\n");
readmeStream.write(
"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n"
);
readmeStream.write(
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\n"
);
readmeStream.write(
"THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
);
// the finish event is emitted when all data has been flushed from the stream
readmeStream.on("finish", () => {
console.log("Created README");
});
// close the stream
readmeStream.end();
});
});
};
exports.writeFile = writeFile;