Changeset 4497463


Ignore:
Timestamp:
Oct 18, 2009 2:06:07 PM (12 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cf10451d
Parents:
10b8441
Message:
  • Router Console translation infrastructure:
    • Persistent lang setting with routerconsole.lang=xx
    • Loading any page with ?lang=xx changes the persistent setting
    • Add a custom Jetty handler to load foo_xx.jsp if it exists for language xx. This is for jsp files with lots of text in them. Otherwise use inline translate methods. Not for included jsps.
    • Add a script to create and update messages_xx.po translation files, and create ResourceBundles? from them
    • Add class to translate strings from cached ResourceBundles?
    • Add translate wrappers to HelperBase?, FormHandler?, and *Renderer, so calls can be made from both jsp and java files
    • Add two example translations on configupdate.jsp - one in the jsp itself and one in the helper.
    • This is for strings in routerconsole only. Will be expanded to other webapps and the router later.
Location:
apps/routerconsole
Files:
5 added
14 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/build.xml

    r10b8441 r4497463  
    7474       
    7575        <ant target="war" />
     76
     77        <!-- Update the messages_*.po files.
     78             We need to supply something for windows, and then change the fail property to true,
     79             or else not run this on windows -->
     80        <exec executable="sh" failifexecutionfails="false" >
     81            <arg value="./bundle-messages.sh" />
     82        </exec>
     83        <!-- jar again to get the latest messages_*.class files -->
     84        <jar destfile="./build/routerconsole.jar" basedir="./build/obj" includes="**/*.class" update="true" />
    7685    </target>
    7786    <target name="war" depends="precompilejsp">
     
    116125       
    117126        <javac debug="true" deprecation="on" source="1.5" target="1.5"
     127               encoding="UTF-8"
    118128               destdir="../jsp/WEB-INF/classes/"
    119129               srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
     
    134144            </classpath>
    135145        </javac>
     146
     147        <!-- save these so we can run gettext on the generated java files later
    136148        <delete>
    137149            <fileset dir="../jsp/WEB-INF/" includes="**/*.java" />
    138150            <fileset dir="../jsp/WEB-INF/" includes="**/*.jsp" />
    139151        </delete>
     152        -->
    140153        <copy file="../jsp/web.xml" tofile="../jsp/web-out.xml" />
    141154        <loadfile property="jspc.web.fragment" srcfile="../jsp/web-fragment.xml" />
  • apps/routerconsole/java/src/net/i2p/router/web/CSSHelper.java

    r10b8441 r4497463  
    2323        return url;
    2424    }
     25
     26    /** change default language for the router but don't save it */
     27    public void setLang(String lang) {
     28        if (lang != null && lang.length() > 0)
     29            _context.router().setConfigSetting(Messages.PROP_LANG, lang);
     30    }
    2531}
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java

    r10b8441 r4497463  
    8888       
    8989        if ("notify".equals(policy))
    90             buf.append("<option value=\"notify\" selected=\"true\">Notify only</option>");
     90            buf.append("<option value=\"notify\" selected=\"true\">").append(_("Notify only")).append("</option>");
    9191        else
    9292            buf.append("<option value=\"notify\">Notify only</option>");
  • apps/routerconsole/java/src/net/i2p/router/web/ContentHelper.java

    r10b8441 r4497463  
    6363    /**
    6464     * Convert file.ext to file_lang.ext if it exists.
    65      * Get lang from either the cgi lang param or from the default locale.
     65     * Get lang from the cgi lang param, then properties, then from the default locale.
     66     * _context must be set to check the property.
    6667     */
    6768    private String filename() {
     
    7172        String lang = _lang;
    7273        if (lang == null || lang.length() <= 0) {
    73             lang = Locale.getDefault().getLanguage();
    74             if (lang == null || lang.length() <= 0)
    75                 return _page;
     74            if (_context != null)
     75                lang = _context.getProperty(Messages.PROP_LANG);
     76            if (lang == null || lang.length() <= 0) {
     77                lang = Locale.getDefault().getLanguage();
     78                if (lang == null || lang.length() <= 0)
     79                    return _page;
     80            }
    7681        }
    7782        if (lang.equals("en"))
  • apps/routerconsole/java/src/net/i2p/router/web/FormHandler.java

    r10b8441 r4497463  
    191191    }
    192192   
     193    /** translate a string */
     194    public String _(String s) {
     195        return Messages.getString(s, _context);
     196    }
    193197}
  • apps/routerconsole/java/src/net/i2p/router/web/HelperBase.java

    r10b8441 r4497463  
    3030
    3131    public void setWriter(Writer out) { _out = out; }
     32
     33    /** translate a string */
     34    public String _(String s) {
     35        return Messages.getString(s, _context);
     36    }
    3237}
  • apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java

    r10b8441 r4497463  
    269269    }
    270270
     271    /** translate a string */
     272    private String _(String s) {
     273        return Messages.getString(s, _context);
     274    }
    271275}
  • apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java

    r10b8441 r4497463  
    320320            return "" + c;
    321321    }
     322
     323    /** translate a string */
     324    private String _(String s) {
     325        return Messages.getString(s, _context);
     326    }
    322327}
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r10b8441 r4497463  
    112112            tmpdir.mkdir();
    113113            wac.setTempDirectory(tmpdir);
     114            wac.addHandler(0, new LocaleWebAppHandler(I2PAppContext.getGlobalContext()));
    114115            initialize(wac);
    115116            File dir = new File(_webAppsDir);
  • apps/routerconsole/java/src/net/i2p/router/web/StatsGenerator.java

    r10b8441 r4497463  
    236236    private final static DecimalFormat _pct = new DecimalFormat("#0.00%");
    237237    private final static String pct(double num) { synchronized (_pct) { return _pct.format(num); } }
     238
     239    /** translate a string */
     240    private String _(String s) {
     241        return Messages.getString(s, _context);
     242    }
    238243}
  • apps/routerconsole/java/src/net/i2p/router/web/TunnelRenderer.java

    r10b8441 r4497463  
    311311        return _context.commSystem().renderPeerHTML(peer);
    312312    }
     313
     314    /** translate a string */
     315    private String _(String s) {
     316        return Messages.getString(s, _context);
     317    }
    313318}
  • apps/routerconsole/jsp/configupdate.jsp

    r10b8441 r4497463  
    3737        </tr><tr><td class= "mediumtags" align="right"><b>Refresh frequency:</b>
    3838          <td><jsp:getProperty name="updatehelper" property="refreshFrequencySelectBox" /></td><tr>
    39           <td class= "mediumtags" align="right"><b>Update policy:</b></td>
     39          <td class= "mediumtags" align="right"><b><%=formhandler._("Update policy")%>:</b></td>
    4040          <td><jsp:getProperty name="updatehelper" property="updatePolicySelectBox" /></td>
    4141        <tr><td class= "mediumtags" align="right"><b>Update through the eepProxy?</b></td>
  • apps/routerconsole/jsp/css.jsp

    r10b8441 r4497463  
    2626<jsp:useBean class="net.i2p.router.web.CSSHelper" id="cssHelper" scope="request" />
    2727<jsp:setProperty name="cssHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
     28<%
     29   cssHelper.setLang(request.getParameter("lang"));
     30%>
    2831<link href="<%=cssHelper.getTheme(request.getHeader("User-Agent"))%>console.css" rel="stylesheet" type="text/css">
    2932<!--[if IE]><link href="/themes/console/classic/ieshim.css" rel="stylesheet" type="text/css" /><![endif]-->
  • apps/routerconsole/jsp/index.jsp

    r10b8441 r4497463  
    3030 <jsp:setProperty name="contenthelper" property="maxLines" value="300" />
    3131 <jsp:setProperty name="contenthelper" property="lang" value="<%=request.getParameter("lang")%>" />
     32 <jsp:setProperty name="contenthelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
    3233 <jsp:getProperty name="contenthelper" property="content" />
    3334</div></body></html>
Note: See TracChangeset for help on using the changeset viewer.