Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 980742a

Browse files
Make multilingual.
1 parent cb13318 commit 980742a

Some content is hidden

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

42 files changed

+3065
-371
lines changed

app/bower.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
],
66
"homepage": "https://www.iotatoken.com/",
77
"dependencies": {
8-
"tingle": "^0.7.0"
8+
"tingle": "^0.7.0",
9+
"i18next": "^8.3.0",
10+
"i18next-xhr-backend": "^1.4.1"
911
}
1012
}

app/css/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ html, body {
208208
background-color: #a4a8ab;
209209
}
210210

211-
label {
211+
label, span.label {
212212
font-weight:bold;
213213
text-align:left;
214214
font-size:22px;
@@ -218,6 +218,10 @@ label {
218218
display: block;
219219
}
220220

221+
span.label {
222+
display: inline-block;
223+
}
224+
221225
input {
222226
box-sizing: border-box;
223227
width: 100%;

app/js/index.js

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const electron = require("electron")
2+
const i18n = electron.remote.getGlobal("i18n");
23

34
var __entityMap = {
45
"&": "&",
@@ -29,12 +30,14 @@ var UI = (function(UI, undefined) {
2930

3031
var showStatusBar = false;
3132
var isFirstRun = false;
33+
var lang = null;
3234

3335
if (typeof(URLSearchParams) != "undefined") {
3436
var params = new URLSearchParams(location.search.slice(1));
3537
showStatusBar = params.get("showStatus") == 1;
3638
isFirstRun = params.get("isFirstRun") == 1;
3739
lightWallet = parseInt(params.get("lightWallet"), 10) == 1;
40+
lang = params.get("lang");
3841
}
3942

4043
if (isFirstRun) {
@@ -72,25 +75,25 @@ var UI = (function(UI, undefined) {
7275
UI.showContextMenu = function(e) {
7376
var template = [
7477
{
75-
label: "Cut",
78+
label: i18n.t("cut"),
7679
accelerator: "CmdOrCtrl+X",
7780
role: "cut",
7881
},
7982
{
80-
label: "Copy",
83+
label: i18n.t("copy"),
8184
accelerator: "CmdOrCtrl+C",
8285
role: "copy"
8386
},
8487
{
85-
label: "Paste",
88+
label: i18n.t("paste"),
8689
accelerator: "CmdOrCtrl+V",
8790
role: "paste"
8891
}
8992
];
9093

9194
if (electron.remote.getCurrentWindow().isFullScreen()) {
9295
template.push({
93-
label: "Exit Fullscreen",
96+
label: i18n.t("exit_fullscreen"),
9497
accelerator: process.platform === "darwin" ? "Ctrl+Command+F" : "F11",
9598
click: function() {
9699
electron.remote.getCurrentWindow().setFullScreen(false);
@@ -185,7 +188,7 @@ var UI = (function(UI, undefined) {
185188

186189
log = log.replace(/\n\s*\n/g, "\n");
187190

188-
UI.showAlert("<h1>Server Log</h1><p>Below are the last messages from the server log (<a href='#' id='copy_server_log'>copy</a>):</p>" +
191+
UI.showAlert("<h1 data-i18n='server_log'>" + i18n.t("server_log") + "</h1><p><span data-i18n='last_messages_from_server_log'>" + i18n.t("last_messages_from_server_log") + "</span> (<a href='#' id='copy_server_log' data-i18n='copy'>" + i18n.t("copy") + "</a>):</p>" +
189192
"<textarea rows='10' class='form-control' id='server_output' style='background:#000;color:#fff;font-family:courier;' readonly>" + String(log).escapeHTML() + "</textarea>", function() {
190193
document.getElementById("copy_server_log").addEventListener("click", function(e) {
191194
e.preventDefault();
@@ -344,10 +347,10 @@ var UI = (function(UI, undefined) {
344347
"</select>");
345348
*/
346349

347-
modal.setContent("<h1>Preferences</h1>" +
348-
(process.platform != "linux" ? "<div class='input-group input-group-last'><label class='label--checkbox'><input type='checkbox' name='open_at_login' id='preferences_open_at_login' class='checkbox' value='1'" + (settings.openAtLogin ? " checked='checked'" : "") + " />Open at Login</label>" : ""));
350+
modal.setContent("<h1 data-i18n='preferences'>" + i18n.t("preferences") + "</h1>" +
351+
(process.platform != "linux" ? "<div class='input-group input-group-last'><label class='label--checkbox'><input type='checkbox' name='open_at_login' id='preferences_open_at_login' class='checkbox' value='1'" + (settings.openAtLogin ? " checked='checked'" : "") + " />" + i18n.t("open_at_login") + "</label>" : ""));
349352

350-
modal.addFooterBtn("Save", "tingle-btn tingle-btn--primary", function() {
353+
modal.addFooterBtn(i18n.t("save"), "tingle-btn tingle-btn--primary", function() {
351354
var settings = {};
352355

353356
if (process.platform != "linux") {
@@ -382,16 +385,16 @@ var UI = (function(UI, undefined) {
382385
}
383386
});
384387

385-
modal.setContent("<h1>Add Neighbor Node</h1>" +
386-
"<p>Are you sure you want to add this node to your server configuration?</p>" +
388+
modal.setContent("<h1 data-i18n='add_neighbor_node'>" + i18n.t("add_neighbor_node") + "</h1>" +
389+
"<p data-i18n='confirm_add_node_to_config'>" + i18n.t("confirm_add_node_to_config") + "</p>" +
387390
"<p style='font-weight:bold'>" + String(node).escapeHTML() + "</p>");
388391

389-
modal.addFooterBtn("Yes, Add This Node", "tingle-btn tingle-btn--primary", function() {
392+
modal.addFooterBtn(i18n.t("yes_add_node"), "tingle-btn tingle-btn--primary", function() {
390393
modal.close();
391394
electron.ipcRenderer.send("addNeighborNode", node);
392395
});
393396

394-
modal.addFooterBtn("No, Cancel", "tingle-btn tingle-btn--default", function() {
397+
modal.addFooterBtn(i18n.t("no_cancel"), "tingle-btn tingle-btn--default", function() {
395398
modal.close();
396399
});
397400

@@ -424,26 +427,27 @@ var UI = (function(UI, undefined) {
424427
var content = "";
425428

426429
if (configuration.lightWallet) {
427-
content = "<h1>Node Config</h1>" +
428-
"<div class='input-group'><label>Host: <span class='error' id='host-error'></span></label>" +
430+
content = "<h1 data-18n='node_config'></h1>" +
431+
"<div class='input-group'><label><span data-i18n='host' class='label'>" + i18n.t("host") + "</span> <span class='error' id='host-error'></span></label>" +
429432
"<input type='text' id='server_config_host' placeholder='' value='" + (configuration.lightWalletHost ? String(configuration.lightWalletHost).escapeHTML() + (configuration.lightWalletPort ? ":" + String(configuration.lightWalletPort).escapeHTML() : "") : "") + "' /></div>" +
430-
"<div class='input-group'><label>Min Weight Magnitude:</label>" +
433+
"<div class='input-group'><label data-i18n='min_weight_magnitude'>" + i18n.t("min_weight_magnitude") + "</label>" +
431434
"<input type='number' min='" + (configuration.testNet ? "13" : "18") + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + (configuration.minWeightMagnitude ? String(configuration.minWeightMagnitude).escapeHTML() : (configuration.testNet ? "13": "18")) + "' /></div>";
432435
} else {
433436
content = "<h1>Node Config</h1>" +
434-
"<div class='input-group'><label>Node Port:</label>" +
437+
"<div class='input-group'><label data-i18n='node_port'>" + i18n.t("node_port") + "</label>" +
435438
"<input type='number' min='1024' name='port' id='server_config_port' placeholder='' value='" + (configuration.port ? String(configuration.port).escapeHTML() : "14265") + "' /></div>" +
436-
"<div class='input-group'><label>Depth:</label>" +
439+
"<div class='input-group'><label data-i18n='depth'>" + i18n.t("depth") + "</label>" +
437440
"<input type='number' min='1' name='depth' id='server_config_depth' placeholder='' value='" + (configuration.depth ? String(configuration.depth).escapeHTML() : "3") + "' /></div>" +
438-
"<div class='input-group'><label>Min Weight Magnitude:</label>" +
441+
"<div class='input-group'><label data-i18n='min_weight_magnitude'>" + i18n.t("min_weight_magnitude") + "</label>" +
439442
"<input type='number' min='" + (configuration.testNet ? "13" : "18") + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + (configuration.minWeightMagnitude ? String(configuration.minWeightMagnitude).escapeHTML() : (configuration.testNet ? "13": "18")) + "' /></div>" +
440-
"<div class='input-group input-group'><label>Neighboring Nodes:</label>" +
441-
"<textarea name='neighboring_nodes' id='server_config_neighboring_nodes' style='width:100%;height:150px;' placeholder='Add nodes in the following format (one per line):\r\n\r\nudp://ip:12345'>" + String(configuration.nodes).escapeHTML() + "</textarea></div>";
443+
"<div class='input-group input-group'><label data-i18n='neighboring_nodes'>" + i18n.t("neighboring_nodes") + "</label>" +
444+
"<textarea name='neighboring_nodes' id='server_config_neighboring_nodes' style='width:100%;height:150px;'>" + String(configuration.nodes).escapeHTML() + "</textarea></div>" +
445+
"<p><span data-i18n='node_settings_format'>" + i18n.t("node_settings_format") + "</span>: udp://ip:12345</p>";
442446
}
443447

444448
modal.setContent(content);
445449

446-
modal.addFooterBtn("Save", "tingle-btn tingle-btn--primary", function() {
450+
modal.addFooterBtn(i18n.t("save"), "tingle-btn tingle-btn--primary", function() {
447451
var config = {};
448452

449453
config.lightWallet = configuration.lightWallet;
@@ -476,7 +480,7 @@ var UI = (function(UI, undefined) {
476480
}
477481

478482
UI.showUpdateAvailable = function() {
479-
UI.showAlert("<h1>Update Available</h1><p>An update is available and is being downloaded.</p>");
483+
UI.showAlert("<h1 data-i18n='update_available'>" + i18n.t("update_available") + "</h1><p data-i18n='update_being_downloaded'>" + i18n.t("update_being_downloaded") + "</p>");
480484
}
481485

482486
UI.showUpdateDownloaded = function(releaseNotes, releaseName, releaseDate) {
@@ -492,34 +496,34 @@ var UI = (function(UI, undefined) {
492496
cssClass: ["update-downloaded"]
493497
});
494498

495-
modal.setContent("<h1>New Update Available...</h1><p>Version " + String(releaseName).escapeHTML() + " is downloaded and ready to install.");
499+
modal.setContent("<h1 data-i18n='new_update_available'>" + i18n.t("new_update_available") + "</h1><p data-i18n='version_is_downloaded_ready_to_install' data-i18n-options={version: " + String(releaseName).escapeHTML() + "}'>" + i18n.t("version_is_downloaded_ready_to_install", {version: String(releaseName).escapeHTML()}) + "</p>");
496500

497-
modal.addFooterBtn("Install Now", "tingle-btn tingle-btn--primary", function() {
501+
modal.addFooterBtn(i18n.t("install_now"), "tingle-btn tingle-btn--primary", function() {
498502
modal.close();
499503
electron.ipcRenderer.send("installUpdate");
500504
});
501505

502-
modal.addFooterBtn("Install on Quit", "tingle-btn tingle-btn--default", function() {
506+
modal.addFooterBtn(i18n.t("install_on_quit"), "tingle-btn tingle-btn--default", function() {
503507
modal.close();
504508
});
505509

506510
modal.open();
507511
}
508512

509513
UI.showUpdateError = function() {
510-
UI.showAlert("<h1>Update Error</h1><p>An error occurred during checking for an update.</p>");
514+
UI.showAlert("<h1 data-i18n='update_error'>" + i18n.t("update_error") + "</h1><p data-i18n='error_during_update_check'>" + i18n.t("error_during_update_check") + "</p>");
511515
}
512516

513517
UI.showCheckingForUpdate = function() {
514518
if (showQuitAlert) {
515519
return;
516520
}
517521

518-
UI.showAlert("<h1>Checking for Updates...</h1><p>Checking for updates, please wait...</p>");
522+
UI.showAlert("<h1 data-i18n='checking_for_updates'>" + i18n.t("checking_for_updates") + "</h1><p data-i18n='checking_for_updates_please_wait'>" + i18n.t("checking_for_updates_please_wait") + "</p>");
519523
}
520524

521525
UI.showUpdateNotAvailable = function() {
522-
UI.showAlert("<h1>No Updates</h1><p>No updates are currently available.</p>");
526+
UI.showAlert("<h1 data-i18n='no_updates'>" + i18n.t("no_updates") + "</h1><p data-i18n='no_updates_available'>" + i18n.t("no_updates_available") + "</p>");
523527
}
524528

525529
UI.showKillAlert = function() {
@@ -532,7 +536,7 @@ var UI = (function(UI, undefined) {
532536
allowClose: false
533537
});
534538

535-
modal.setContent("<h1>Shutdown In Progress</h1><p style='margin-bottom:0'>Shutting down IOTA... Please wait.</p>");
539+
modal.setContent("<h1 data-i18n='shutdown_in_progress'>" + i18n.t("shutdown_in_progress") + "</h1><p style='margin-bottom:0' data-i18n='shutting_down_iota'>" + i18n.t("shutting_down_iota") + "</p>");
536540

537541
modal.open();
538542
}
@@ -573,7 +577,7 @@ var UI = (function(UI, undefined) {
573577

574578
modal.setContent(msg);
575579

576-
modal.addFooterBtn("OK", "tingle-btn tingle-btn--primary", function() {
580+
modal.addFooterBtn(i18n.t("ok"), "tingle-btn tingle-btn--primary", function() {
577581
modal.close();
578582
});
579583

@@ -590,7 +594,7 @@ var UI = (function(UI, undefined) {
590594
UI.hideAlerts();
591595

592596
if (!msg) {
593-
msg = "<h1>Error</h1><p>An error occurred, the server has quit. Please restart the application.</p>";
597+
msg = "<h1 data-i18n='error'>" + i18n.t("error") + "</h1><p data-i18n='error_please_restart'>" + i18n.t("error_please_restart") + "</p>";
594598
}
595599

596600
if (serverOutput && serverOutput.length) {
@@ -614,7 +618,7 @@ var UI = (function(UI, undefined) {
614618

615619
modal.setContent(html);
616620

617-
modal.addFooterBtn("OK", "tingle-btn tingle-btn--primary", function() {
621+
modal.addFooterBtn(i18n.t("ok"), "tingle-btn tingle-btn--primary", function() {
618622
modal.close();
619623
});
620624

@@ -659,6 +663,16 @@ var UI = (function(UI, undefined) {
659663
}
660664
}
661665

666+
UI.changeLanguage = function(language) {
667+
var i18nList = document.querySelectorAll('[data-i18n]');
668+
i18nList.forEach(function(v){
669+
v.innerHTML = i18n.t(v.dataset.i18n, v.dataset.i18nOptions);
670+
});
671+
if (webviewIsLoaded && webview) {
672+
webview.send("changeLanguage", language);
673+
}
674+
}
675+
662676
UI.handleURL = function(url) {
663677
// Disable for now.
664678
return;
@@ -867,6 +881,10 @@ electron.ipcRenderer.on("notify", function(event, type, message, options) {
867881
UI.notify(type, message, options);
868882
});
869883

884+
electron.ipcRenderer.on("changeLanguage", function(event, language) {
885+
UI.changeLanguage(language);
886+
});
887+
870888
electron.ipcRenderer.on("relaunch", UI.relaunch);
871889

872890
electron.ipcRenderer.on("shutdown", UI.shutdown);

0 commit comments

Comments
 (0)