1
1
const electron = require ( "electron" )
2
+ const i18n = electron . remote . getGlobal ( "i18n" ) ;
2
3
3
4
var __entityMap = {
4
5
"&" : "&" ,
@@ -29,12 +30,14 @@ var UI = (function(UI, undefined) {
29
30
30
31
var showStatusBar = false ;
31
32
var isFirstRun = false ;
33
+ var lang = null ;
32
34
33
35
if ( typeof ( URLSearchParams ) != "undefined" ) {
34
36
var params = new URLSearchParams ( location . search . slice ( 1 ) ) ;
35
37
showStatusBar = params . get ( "showStatus" ) == 1 ;
36
38
isFirstRun = params . get ( "isFirstRun" ) == 1 ;
37
39
lightWallet = parseInt ( params . get ( "lightWallet" ) , 10 ) == 1 ;
40
+ lang = params . get ( "lang" ) ;
38
41
}
39
42
40
43
if ( isFirstRun ) {
@@ -72,25 +75,25 @@ var UI = (function(UI, undefined) {
72
75
UI . showContextMenu = function ( e ) {
73
76
var template = [
74
77
{
75
- label : "Cut" ,
78
+ label : i18n . t ( "cut" ) ,
76
79
accelerator : "CmdOrCtrl+X" ,
77
80
role : "cut" ,
78
81
} ,
79
82
{
80
- label : "Copy" ,
83
+ label : i18n . t ( "copy" ) ,
81
84
accelerator : "CmdOrCtrl+C" ,
82
85
role : "copy"
83
86
} ,
84
87
{
85
- label : "Paste" ,
88
+ label : i18n . t ( "paste" ) ,
86
89
accelerator : "CmdOrCtrl+V" ,
87
90
role : "paste"
88
91
}
89
92
] ;
90
93
91
94
if ( electron . remote . getCurrentWindow ( ) . isFullScreen ( ) ) {
92
95
template . push ( {
93
- label : "Exit Fullscreen" ,
96
+ label : i18n . t ( "exit_fullscreen" ) ,
94
97
accelerator : process . platform === "darwin" ? "Ctrl+Command+F" : "F11" ,
95
98
click : function ( ) {
96
99
electron . remote . getCurrentWindow ( ) . setFullScreen ( false ) ;
@@ -185,7 +188,7 @@ var UI = (function(UI, undefined) {
185
188
186
189
log = log . replace ( / \n \s * \n / g, "\n" ) ;
187
190
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>" +
189
192
"<textarea rows='10' class='form-control' id='server_output' style='background:#000;color:#fff;font-family:courier;' readonly>" + String ( log ) . escapeHTML ( ) + "</textarea>" , function ( ) {
190
193
document . getElementById ( "copy_server_log" ) . addEventListener ( "click" , function ( e ) {
191
194
e . preventDefault ( ) ;
@@ -344,10 +347,10 @@ var UI = (function(UI, undefined) {
344
347
"</select>");
345
348
*/
346
349
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>" : "" ) ) ;
349
352
350
- modal . addFooterBtn ( "Save" , "tingle-btn tingle-btn--primary" , function ( ) {
353
+ modal . addFooterBtn ( i18n . t ( "save" ) , "tingle-btn tingle-btn--primary" , function ( ) {
351
354
var settings = { } ;
352
355
353
356
if ( process . platform != "linux" ) {
@@ -382,16 +385,16 @@ var UI = (function(UI, undefined) {
382
385
}
383
386
} ) ;
384
387
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>" +
387
390
"<p style='font-weight:bold'>" + String ( node ) . escapeHTML ( ) + "</p>" ) ;
388
391
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 ( ) {
390
393
modal . close ( ) ;
391
394
electron . ipcRenderer . send ( "addNeighborNode" , node ) ;
392
395
} ) ;
393
396
394
- modal . addFooterBtn ( "No, Cancel" , "tingle-btn tingle-btn--default" , function ( ) {
397
+ modal . addFooterBtn ( i18n . t ( "no_cancel" ) , "tingle-btn tingle-btn--default" , function ( ) {
395
398
modal . close ( ) ;
396
399
} ) ;
397
400
@@ -424,26 +427,27 @@ var UI = (function(UI, undefined) {
424
427
var content = "" ;
425
428
426
429
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>" +
429
432
"<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>" +
431
434
"<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>" ;
432
435
} else {
433
436
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>" +
435
438
"<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>" +
437
440
"<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>" +
439
442
"<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>" ;
442
446
}
443
447
444
448
modal . setContent ( content ) ;
445
449
446
- modal . addFooterBtn ( "Save" , "tingle-btn tingle-btn--primary" , function ( ) {
450
+ modal . addFooterBtn ( i18n . t ( "save" ) , "tingle-btn tingle-btn--primary" , function ( ) {
447
451
var config = { } ;
448
452
449
453
config . lightWallet = configuration . lightWallet ;
@@ -476,7 +480,7 @@ var UI = (function(UI, undefined) {
476
480
}
477
481
478
482
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>") ;
480
484
}
481
485
482
486
UI . showUpdateDownloaded = function ( releaseNotes , releaseName , releaseDate ) {
@@ -492,34 +496,34 @@ var UI = (function(UI, undefined) {
492
496
cssClass : [ "update-downloaded" ]
493
497
} ) ;
494
498
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> ") ;
496
500
497
- modal . addFooterBtn ( "Install Now" , "tingle-btn tingle-btn--primary" , function ( ) {
501
+ modal . addFooterBtn ( i18n . t ( "install_now" ) , "tingle-btn tingle-btn--primary" , function ( ) {
498
502
modal . close ( ) ;
499
503
electron . ipcRenderer . send ( "installUpdate" ) ;
500
504
} ) ;
501
505
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 ( ) {
503
507
modal . close ( ) ;
504
508
} ) ;
505
509
506
510
modal . open ( ) ;
507
511
}
508
512
509
513
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>") ;
511
515
}
512
516
513
517
UI . showCheckingForUpdate = function ( ) {
514
518
if ( showQuitAlert ) {
515
519
return ;
516
520
}
517
521
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>") ;
519
523
}
520
524
521
525
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>") ;
523
527
}
524
528
525
529
UI . showKillAlert = function ( ) {
@@ -532,7 +536,7 @@ var UI = (function(UI, undefined) {
532
536
allowClose : false
533
537
} ) ;
534
538
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>") ;
536
540
537
541
modal . open ( ) ;
538
542
}
@@ -573,7 +577,7 @@ var UI = (function(UI, undefined) {
573
577
574
578
modal . setContent ( msg ) ;
575
579
576
- modal . addFooterBtn ( "OK" , "tingle-btn tingle-btn--primary" , function ( ) {
580
+ modal . addFooterBtn ( i18n . t ( "ok" ) , "tingle-btn tingle-btn--primary" , function ( ) {
577
581
modal . close ( ) ;
578
582
} ) ;
579
583
@@ -590,7 +594,7 @@ var UI = (function(UI, undefined) {
590
594
UI . hideAlerts ( ) ;
591
595
592
596
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>";
594
598
}
595
599
596
600
if ( serverOutput && serverOutput . length ) {
@@ -614,7 +618,7 @@ var UI = (function(UI, undefined) {
614
618
615
619
modal . setContent ( html ) ;
616
620
617
- modal . addFooterBtn ( "OK" , "tingle-btn tingle-btn--primary" , function ( ) {
621
+ modal . addFooterBtn ( i18n . t ( "ok" ) , "tingle-btn tingle-btn--primary" , function ( ) {
618
622
modal . close ( ) ;
619
623
} ) ;
620
624
@@ -659,6 +663,16 @@ var UI = (function(UI, undefined) {
659
663
}
660
664
}
661
665
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
+
662
676
UI . handleURL = function ( url ) {
663
677
// Disable for now.
664
678
return ;
@@ -867,6 +881,10 @@ electron.ipcRenderer.on("notify", function(event, type, message, options) {
867
881
UI . notify ( type , message , options ) ;
868
882
} ) ;
869
883
884
+ electron . ipcRenderer . on ( "changeLanguage" , function ( event , language ) {
885
+ UI . changeLanguage ( language ) ;
886
+ } ) ;
887
+
870
888
electron . ipcRenderer . on ( "relaunch" , UI . relaunch ) ;
871
889
872
890
electron . ipcRenderer . on ( "shutdown" , UI . shutdown ) ;
0 commit comments