diff --git a/apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java index 7fe42a3ba..8fcbd65c0 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java @@ -63,7 +63,7 @@ public class UnsignedUpdateHandler extends UpdateHandler { /** Get the file */ @Override protected void update() { - _status = "Updating"; + updateStatus("" + _("Updating") + ""); if (_log.shouldLog(Log.DEBUG)) _log.debug("Starting unsigned update URL: " + _zipURL); // always proxy for now @@ -85,10 +85,10 @@ public class UnsignedUpdateHandler extends UpdateHandler { public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) { File updFile = new File(_updateFile); if (FileUtil.verifyZip(updFile)) { - _status = "Update downloaded"; + updateStatus("" + _("Update downloaded") + ""); } else { updFile.delete(); - _status = "Unsigned update file is corrupt from " + url; + updateStatus("" + _("Unsigned update file from {0} is corrupt", url) + ""); _log.log(Log.CRIT, "Corrupt zip file from " + url); return; } @@ -108,20 +108,22 @@ public class UnsignedUpdateHandler extends UpdateHandler { _context.router().saveConfig(); if ("install".equals(policy)) { _log.log(Log.CRIT, "Update was downloaded, restarting to install it"); - _status = "Update downloaded
Restarting"; + updateStatus("" + _("Update downloaded") + "
" + _("Restarting")); restart(); } else { _log.log(Log.CRIT, "Update was downloaded, will be installed at next restart"); - _status = "Update downloaded
"; + StringBuilder buf = new StringBuilder(64); + buf.append("").append(_("Update downloaded")).append("
"); if (System.getProperty("wrapper.version") != null) - _status += "Click Restart to install"; + buf.append(_("Click Restart to install")); else - _status += "Click Shutdown and restart to install"; - _status += " Version " + _zipVersion; + buf.append(_("Click Shutdown and restart to install")); + buf.append(' ').append(_("Version {0}", _zipVersion)); + updateStatus(buf.toString()); } } else { _log.log(Log.CRIT, "Failed copy to " + to); - _status = "Failed copy to " + to + ""; + updateStatus("" + _("Failed copy to {0}", to) + ""); } } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java index 43cb6850f..050f0f975 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java @@ -32,7 +32,7 @@ public class UpdateHandler { protected RouterContext _context; protected Log _log; protected String _updateFile; - protected static String _status = ""; + private static String _status = ""; private String _action; private String _nonce; @@ -129,7 +129,7 @@ public class UpdateHandler { public UpdateRunner() { _isRunning = false; this.done = false; - _status = "Updating"; + updateStatus("" + _("Updating") + ""); } public boolean isRunning() { return _isRunning; } public boolean isDone() { @@ -142,7 +142,7 @@ public class UpdateHandler { _isRunning = false; } protected void update() { - _status = "Updating"; + updateStatus("" + _("Updating") + ""); String updateURL = selectUpdateURL(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Selected update URL: " + updateURL); @@ -169,19 +169,18 @@ public class UpdateHandler { } public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) { StringBuilder buf = new StringBuilder(64); - buf.append("Updating "); + buf.append("").append(_("Updating")).append(" "); double pct = ((double)alreadyTransferred + (double)currentWrite) / ((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining); synchronized (_pct) { buf.append(_pct.format(pct)); } buf.append(":
\n"); - buf.append(DataHelper.formatSize(currentWrite + alreadyTransferred)); - buf.append("B transferred"); - _status = buf.toString(); + buf.append(_("{0}B transferred", DataHelper.formatSize(currentWrite + alreadyTransferred))); + updateStatus(buf.toString()); } public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) { - _status = "Update downloaded"; + updateStatus("" + _("Update downloaded") + ""); TrustedUpdate up = new TrustedUpdate(_context); File f = new File(_updateFile); File to = new File(_context.getRouterDir(), Router.UPDATE_FILE); @@ -201,22 +200,23 @@ public class UpdateHandler { _context.router().saveConfig(); if ("install".equals(policy)) { _log.log(Log.CRIT, "Update was VERIFIED, restarting to install it"); - _status = "Update verified
Restarting"; + updateStatus("" + _("Update verified") + "
" + _("Restarting")); restart(); } else { _log.log(Log.CRIT, "Update was VERIFIED, will be installed at next restart"); - _status = "Update downloaded
"; + StringBuilder buf = new StringBuilder(64); + buf.append("").append(_("Update downloaded")).append("
"); if (System.getProperty("wrapper.version") != null) - _status += "Click Restart to install"; + buf.append(_("Click Restart to install")); else - _status += "Click Shutdown and restart to install"; + buf.append(_("Click Shutdown and restart to install")); if (up.newVersion() != null) - _status += " Version " + up.newVersion(); + buf.append(' ').append(_("Version {0}", up.newVersion())); + updateStatus(buf.toString()); } } else { - err = err + " from " + url; - _log.log(Log.CRIT, err); - _status = "" + err + ""; + _log.log(Log.CRIT, err + " from " + url); + updateStatus("" + err + ' ' + _("from {0}", url) + " "); } } public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) { @@ -224,7 +224,7 @@ public class UpdateHandler { _log.log(Log.CRIT, "Update from " + url + " did not download completely (" + bytesRemaining + " remaining after " + currentAttempt + " tries)"); - _status = "Transfer failed"; + updateStatus("" + _("Transfer failed") + ""); } public void headerReceived(String url, int attemptNum, String key, String val) {} public void attempting(String url) {} @@ -251,4 +251,30 @@ public class UpdateHandler { _log.log(Log.DEBUG, "Picked update source " + index + "."); return (String) URLList.get(index); } + + protected void updateStatus(String s) { + _status = s; + } + + /** translate a string */ + protected String _(String s) { + return Messages.getString(s, _context); + } + + /** + * translate a string with a parameter + * This is a lot more expensive than _(s), so use sparingly. + * + * @param s string to be translated containing {0} + * The {0} will be replaced by the parameter. + * Single quotes must be doubled, i.e. ' -> '' in the string. + * @param o parameter, not translated. + * To tranlslate parameter also, use _("foo {0} bar", _("baz")) + * Do not double the single quotes in the parameter. + * Use autoboxing to call with ints, longs, floats, etc. + */ + protected String _(String s, Object o) { + return Messages.getString(s, o, _context); + } + }