From 9bf22fb0d336b47dd66d40545eeb0a2356f8a33e Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sat, 19 Dec 2009 17:41:47 +0000
Subject: [PATCH] stats.jsp tagging

---
 .../net/i2p/router/web/StatsGenerator.java    | 29 +++++++++++--------
 apps/routerconsole/java/strings/Strings.java  | 19 ++++++++++++
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/StatsGenerator.java b/apps/routerconsole/java/src/net/i2p/router/web/StatsGenerator.java
index 9ac1ae5422..4ddc6e6f45 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/StatsGenerator.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/StatsGenerator.java
@@ -40,7 +40,7 @@ public class StatsGenerator {
             String group = (String)entry.getKey();
             Set stats = (Set)entry.getValue();
             buf.append("<option value=\"/stats.jsp#").append(group).append("\">");
-            buf.append(group).append("</option>\n");
+            buf.append(_(group)).append("</option>\n");
             for (Iterator statIter = stats.iterator(); statIter.hasNext(); ) {
                 String stat = (String)statIter.next();
                 buf.append("<option value=\"/stats.jsp#");
@@ -52,7 +52,7 @@ public class StatsGenerator {
             out.write(buf.toString());
             buf.setLength(0);
         }
-        buf.append("</select> <input type=\"submit\" value=\"GO\" />");
+        buf.append("</select> <input type=\"submit\" value=\"").append(_("GO")).append("\" />");
         buf.append("</form>");
         
         buf.append(_("Statistics gathered during this router's uptime")).append(" (");
@@ -69,7 +69,7 @@ public class StatsGenerator {
             buf.append("<h3><a name=\"");
             buf.append(group);
             buf.append("\">");
-            buf.append(group);
+            buf.append(_(group));
             buf.append("</a></h3>");
             buf.append("<ul>");
             out.write(buf.toString());
@@ -104,7 +104,7 @@ public class StatsGenerator {
         for (int i = 0; i < periods.length; i++) {
             if (periods[i] > uptime)
                 break;
-            renderPeriod(buf, periods[i], "frequency");
+            renderPeriod(buf, periods[i], _("frequency"));
             Frequency curFreq = freq.getFrequency(periods[i]);
             buf.append(" <i>avg per period:</i> (");
             buf.append(num(curFreq.getAverageEventsPerPeriod()));
@@ -138,7 +138,7 @@ public class StatsGenerator {
             buf.append("</i><br>");
         }
         if (rate.getLifetimeEventCount() <= 0) {
-            buf.append("No lifetime events<br>\n");
+            buf.append(_("No lifetime events")).append("<br>\n");
             return;
         }
         long now = _context.clock().now();
@@ -150,9 +150,9 @@ public class StatsGenerator {
             if (curRate.getLastCoalesceDate() <= curRate.getCreationDate())
                 break;
             buf.append("<li>");
-            renderPeriod(buf, periods[i], "rate");
+            renderPeriod(buf, periods[i], _("rate"));
             if (curRate.getLastEventCount() > 0) {
-                buf.append( "<i>avg value:</i> (");
+                buf.append( "<i>").append(_("avg value")).append(":</i> (");
                 buf.append(num(curRate.getAverageValue()));
                 buf.append(" peak ");
                 buf.append(num(curRate.getExtremeAverageValue()));
@@ -181,21 +181,21 @@ public class StatsGenerator {
                     buf.append(num(curRate.getExtremeSaturationLimit()));
                     buf.append(")");
                 }
-                buf.append(" <i>events:</i> ");
+                buf.append(" <i>").append(_("events")).append(":</i> ");
                 buf.append(curRate.getLastEventCount());
                 buf.append(" <i>in this period which ended:</i> ");
                 buf.append(DataHelper.formatDuration(now - curRate.getLastCoalesceDate()));
                 buf.append(" ago ");
             } else {
-                buf.append(" <i>No events</i> ");
+                buf.append(" <i>").append(_("No events")).append("</i> ");
             }
             long numPeriods = curRate.getLifetimePeriods();
             if (numPeriods > 0) {
                 double avgFrequency = curRate.getLifetimeEventCount() / (double)numPeriods;
                 double peakFrequency = curRate.getExtremeEventCount();
-                buf.append(" (lifetime average: ");
+                buf.append(" (").append(_("lifetime average")).append(": ");
                 buf.append(num(avgFrequency));
-                buf.append(", peak average: ");
+                buf.append(", ").append(_("peak average")).append(": ");
                 buf.append(curRate.getExtremeEventCount());
                 buf.append(")");
             }
@@ -213,7 +213,7 @@ public class StatsGenerator {
             buf.append("</li>\n");
         }
         // Display the strict average
-        buf.append("<li><b>lifetime average value:</b> ");
+        buf.append("<li><b>").append(_("lifetime average value")).append(":</b> ");
         buf.append(num(rate.getLifetimeAverageValue()));
         buf.append(" over ");
         buf.append(rate.getLifetimeEventCount());
@@ -240,4 +240,9 @@ public class StatsGenerator {
     private String _(String s) {
         return Messages.getString(s, _context);
     }
+
+    /** translate a string */
+    private String _(String s, Object o) {
+        return Messages.getString(s, o, _context);
+    }
 }
diff --git a/apps/routerconsole/java/strings/Strings.java b/apps/routerconsole/java/strings/Strings.java
index cddec4197b..0805d479a1 100644
--- a/apps/routerconsole/java/strings/Strings.java
+++ b/apps/routerconsole/java/strings/Strings.java
@@ -52,5 +52,24 @@ class Dummy {
         _("dark");
         _("light");
         _("midnight");        
+
+        // stat groups for stats.jsp
+        _("Bandwidth");
+        _("BandwidthLimiter");
+        _("ClientMessages");
+        _("Encryption");
+        _("i2cp");
+        _("I2PTunnel");
+        _("InNetPool");
+        _("JobQueue");
+        _("NetworkDatabase");
+        _("ntcp");
+        _("Peers");
+        _("Router");
+        _("Stream");
+        _("Throttle");
+        _("Transport");
+        _("Tunnels");
+        _("udp");
     }
 }
-- 
GitLab