* Console:
- Add parameterized tag - Refactor confignav.jsp to java and tag - Start tagging profiles.jsp
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* refactored from confignav.jsp to reduce size and make translation easier
|
||||
* @author zzz
|
||||
*/
|
||||
public class ConfigNavHelper extends HelperBase {
|
||||
|
||||
/** configX.jsp */
|
||||
private static final String pages[] =
|
||||
{"", "ui", "service", "update", "tunnels",
|
||||
"clients", "peer", "keyring", "logging", "stats",
|
||||
"advanced" };
|
||||
|
||||
private static final String titles[] =
|
||||
{_x("Network"), _x("UI"), _x("Service"), _x("Update"), _x("Tunnels"),
|
||||
_x("Clients"), _x("Peers"), _x("Keyring"), _x("Logging"), _x("Stats"),
|
||||
_x("Advanced") };
|
||||
|
||||
public void renderNavBar(String requestURI) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
String page = "config" + pages[i] + ".jsp";
|
||||
if (requestURI.indexOf(page) != -1) {
|
||||
// we are there
|
||||
buf.append(_(titles[i]));
|
||||
} else {
|
||||
// we are not there, make a link
|
||||
buf.append("<a href=\"").append(page).append("\">").append(_(titles[i])).append("</a>");
|
||||
}
|
||||
if (i != pages.length - 1)
|
||||
buf.append(" |\n");
|
||||
}
|
||||
_out.write(buf.toString());
|
||||
}
|
||||
}
|
@ -194,4 +194,21 @@ public class FormHandler {
|
||||
public 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.
|
||||
*/
|
||||
public String _(String s, Object o) {
|
||||
return Messages.getString(s, o, _context);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,22 @@ public abstract class HelperBase {
|
||||
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.
|
||||
*/
|
||||
public String _(String s, Object o) {
|
||||
return Messages.getString(s, o, _context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a string for extraction by xgettext and translation.
|
||||
* Use this only in static initializers.
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
@ -54,6 +55,34 @@ public class Messages {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* translate a string with a parameter
|
||||
* This is a lot more expensive than getString(s, ctx), 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.
|
||||
*/
|
||||
public static String getString(String s, Object o, I2PAppContext ctx) {
|
||||
String x = getString(s, ctx);
|
||||
Object[] oArray = new Object[1];
|
||||
oArray[0] = o;
|
||||
try {
|
||||
MessageFormat fmt = new MessageFormat(x, new Locale(getLanguage(ctx)));
|
||||
return fmt.format(oArray, new StringBuffer(), null).toString();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.err.println("Bad format: orig: \"" + s +
|
||||
"\" trans: \"" + x +
|
||||
"\" param: \"" + o +
|
||||
"\" lang: " + getLanguage(ctx));
|
||||
return "FIXME: " + x + ' ' + o;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLanguage(I2PAppContext ctx) {
|
||||
String lang = ctx.getProperty(PROP_LANG);
|
||||
if (lang == null || lang.length() <= 0)
|
||||
|
@ -60,16 +60,18 @@ class ProfileOrganizerRenderer {
|
||||
int integrated = 0;
|
||||
int failing = 0;
|
||||
StringBuilder buf = new StringBuilder(16*1024);
|
||||
buf.append("<h2>Peer Profiles</h2>\n");
|
||||
buf.append("<p>Showing ").append(order.size()).append(" recent profiles, hiding ").append(peers.size()-order.size()).append(" older profiles</p>");
|
||||
buf.append("<table>" +
|
||||
buf.append("<h2>Peer Profiles</h2>\n<p>");
|
||||
buf.append(_("Showing {0} recent profiles.", order.size())).append('\n');
|
||||
buf.append(_("Hiding {0} older profiles.", peers.size()-order.size()));
|
||||
buf.append("</p>" +
|
||||
"<table>" +
|
||||
"<tr>" +
|
||||
"<th>Peer</th>" +
|
||||
"<th>Groups (Caps)</th>" +
|
||||
"<th>Speed</th>" +
|
||||
"<th>Capacity</th>" +
|
||||
"<th>Integration</th>" +
|
||||
"<th>Status</th>" +
|
||||
"<th>").append(_("Peer")).append("</th>" +
|
||||
"<th>").append(_("Groups (Caps)")).append("</th>" +
|
||||
"<th>").append(_("Speed")).append("</th>" +
|
||||
"<th>").append(_("Capacity")).append("</th>" +
|
||||
"<th>").append(_("Integration")).append("</th>" +
|
||||
"<th>").append(_("Status")).append("</th>" +
|
||||
"<th> </th>" +
|
||||
"</tr>");
|
||||
int prevTier = 1;
|
||||
@ -324,4 +326,20 @@ class ProfileOrganizerRenderer {
|
||||
private 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.
|
||||
*/
|
||||
public String _(String s, Object o) {
|
||||
return Messages.getString(s, o, _context);
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,15 @@
|
||||
<%
|
||||
/*
|
||||
* Included ~10 times, keep whitespace to a minimum
|
||||
*/
|
||||
%>
|
||||
<jsp:useBean class="net.i2p.router.web.ConfigNavHelper" id="navHelper" scope="request" />
|
||||
<jsp:setProperty name="navHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<jsp:setProperty name="navHelper" property="writer" value="<%=out%>" />
|
||||
<div class="confignav" id="confignav">
|
||||
<center>
|
||||
<% if (request.getRequestURI().indexOf("config.jsp") != -1) {
|
||||
%>Network | <% } else { %><a href="config.jsp">Network</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configui.jsp") != -1) {
|
||||
%>UI | <% } else { %><a href="configui.jsp">UI</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configservice.jsp") != -1) {
|
||||
%>Service | <% } else { %><a href="configservice.jsp">Service</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configupdate.jsp") != -1) {
|
||||
%>Update | <% } else { %><a href="configupdate.jsp">Update</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configtunnels.jsp") != -1) {
|
||||
%>Tunnels | <% } else { %><a href="configtunnels.jsp">Tunnels</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configclients.jsp") != -1) {
|
||||
%>Clients | <% } else { %><a href="configclients.jsp">Clients</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configpeer.jsp") != -1) {
|
||||
%>Peers | <% } else { %><a href="configpeer.jsp">Peers</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configkeyring.jsp") != -1) {
|
||||
%>Keyring | <% } else { %><a href="configkeyring.jsp">Keyring</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configlogging.jsp") != -1) {
|
||||
%>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configstats.jsp") != -1) {
|
||||
%>Stats | <% } else { %><a href="configstats.jsp">Stats</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configadvanced.jsp") != -1) {
|
||||
%>Advanced<% } else { %><a href="configadvanced.jsp">Advanced</a><% } %>
|
||||
<%
|
||||
// moved to java for ease of translation and to avoid 10 copies
|
||||
navHelper.renderNavBar(request.getRequestURI());
|
||||
%>
|
||||
</center></div>
|
||||
|
Reference in New Issue
Block a user