changeset 3376:653dd9d7f5d5

FixA: Introduce i18n to overview transformation. flys-client/trunk@5093 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 21 Jul 2012 13:13:21 +0000
parents 87c0a06743b8
children a5c790ed09bd
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl
diffstat 3 files changed, 119 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Jul 20 14:09:53 2012 +0000
+++ b/flys-client/ChangeLog	Sat Jul 21 13:13:21 2012 +0000
@@ -1,3 +1,13 @@
+2012-07-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl:
+	  Bring in sync with transformation in flys-client. Current weakness:
+	  Only english and german locales are supported.
+
+	* src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java:
+	  Depending on client given locale call transformation with
+	  locale "de" or "en".
+
 2012-07-20	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl: Merged
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java	Fri Jul 20 14:09:53 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java	Sat Jul 21 13:13:21 2012 +0000
@@ -58,8 +58,8 @@
         String  locale,
         String  uuid,
         String  filter,
-        boolean  checkboxes,
-        String   callback
+        boolean checkboxes,
+        String  callback
     )
     throws ServerException
     {
@@ -100,8 +100,8 @@
                 log.debug(XMLUtils.toString(resultDoc));
             }
 
-            FixingsOverviewInfo i =
-                getInfo(resultDoc, uuid, checkboxes, callback);
+            FixingsOverviewInfo i = getInfo(
+                locale, resultDoc, uuid, checkboxes, callback);
             return i;
         }
         catch (ConnectionException ce) {
@@ -112,11 +112,17 @@
 
 
     protected FixingsOverviewInfo getInfo(
+        String   locale,
         Document doc,
         String   uuid,
         boolean  checkboxes,
         String   callback
     ) {
+        // TODO: Find a more general solution.
+        locale = locale == null || locale.toLowerCase().startsWith("de")
+            ? "de"
+            : "en";
+
         InputStream transform = getServletContext()
             .getResourceAsStream(XSL_TRANSFORM);
 
@@ -128,6 +134,7 @@
         String result = null;
         try {
             XSLTransformer xformer = new XSLTransformer();
+            xformer.addParameter("locale", locale);
             xformer.addParameter("project-uuid", uuid);
             xformer.addParameter(
                 "render-checkboxes",
@@ -166,12 +173,12 @@
 
         List<FixEvent> fixEvents = getFixEvents(doc);
         return new FixingsOverviewInfo(
-                rid,
-                river,
-                from,
-                to,
-                fixEvents,
-                result);
+            rid,
+            river,
+            from,
+            to,
+            fixEvents,
+            result);
     }
 
 
--- a/flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl	Fri Jul 20 14:09:53 2012 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl	Sat Jul 21 13:13:21 2012 +0000
@@ -9,6 +9,79 @@
   <xsl:param name="render-checkboxes" select="true()"/>
   <xsl:param name="callback"/>
 
+  <xsl:param name="locale">de</xsl:param>
+
+  <xsl:decimal-format name="de" decimal-separator=',' grouping-separator='.'/>
+  <xsl:decimal-format name="en" decimal-separator='.' grouping-separator=','/>
+
+  <!-- XXX: This kind of i18n is cheesy.
+            It should be better done in an external resource. -->
+
+  <xsl:variable name="km-pattern">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">0,##</xsl:when>
+      <xsl:otherwise>0.##</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-event">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">Ereignis</xsl:when>
+      <xsl:otherwise>Event</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-legend">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">Legende</xsl:when>
+      <xsl:otherwise>Caption</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-color">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">Farbe</xsl:when>
+      <xsl:otherwise>Color</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-meaning">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">Bedeutung</xsl:when>
+      <xsl:otherwise>Meaning</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-around-mnq">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">um MNQ</xsl:when>
+      <xsl:otherwise>around MNQ</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-around-mq">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">um MQ</xsl:when>
+      <xsl:otherwise>around MQ</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-around-mhq">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">um MHQ</xsl:when>
+      <xsl:otherwise>around MHQ</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="i18n-above-hq5">
+    <xsl:choose>
+      <xsl:when test="$locale = 'de'">über HQ5</xsl:when>
+      <xsl:otherwise>above HQ5</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <!-- TODO: Format dates according locale. -->
+
   <xsl:template match="@*" mode="min">
     <xsl:if test="position() = 1">
       <xsl:value-of select="number(.)"/>
@@ -23,7 +96,7 @@
 
   <xsl:variable name="global-min">
     <xsl:choose>
-      <xsl:when test="count(/fixings/events/event) &gt; 0">
+      <xsl:when test="count(/fixings/events/event/sector) &gt; 0">
         <xsl:apply-templates mode="min" select="/fixings/events/event/sector/@from">
           <xsl:sort data-type="number" select="."/>
         </xsl:apply-templates>
@@ -36,7 +109,7 @@
 
   <xsl:variable name="global-max">
     <xsl:choose>
-      <xsl:when test="count(/fixings/events/event) &gt; 0">
+      <xsl:when test="count(/fixings/events/event/sector) &gt; 0">
         <xsl:apply-templates mode="max" select="/fixings/events/event/sector/@to">
           <xsl:sort data-type="number" select="."/>
         </xsl:apply-templates>
@@ -165,14 +238,14 @@
       </xsl:attribute>
       <xsl:attribute name="title">
         <xsl:text>km </xsl:text>
-        <xsl:value-of select="@from"/>
+        <xsl:value-of select="format-number(@from, $km-pattern, $locale)"/>
         <xsl:text> - </xsl:text>
-        <xsl:value-of select="@to"/>
+        <xsl:value-of select="format-number(@to, $km-pattern, $locale)"/>
         <xsl:choose>
-          <xsl:when test="@class = '0'"> / Q um MNQ</xsl:when>
-          <xsl:when test="@class = '1'"> / Q um MQ</xsl:when>
-          <xsl:when test="@class = '2'"> / Q um MHQ</xsl:when>
-          <xsl:when test="@class = '3'"> / Q über HQ5</xsl:when>
+          <xsl:when test="@class = '0'"> / Q <xsl:value-of select="$i18n-around-mnq"/></xsl:when>
+          <xsl:when test="@class = '1'"> / Q <xsl:value-of select="$i18n-around-mq"/></xsl:when>
+          <xsl:when test="@class = '2'"> / Q <xsl:value-of select="$i18n-around-mhq"/></xsl:when>
+          <xsl:when test="@class = '3'"> / Q <xsl:value-of select="$i18n-above-hq5"/></xsl:when>
         </xsl:choose>
       </xsl:attribute>
       <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
@@ -205,7 +278,7 @@
         <xsl:text>overflow:hidden;background:</xsl:text>
         <xsl:choose>
           <xsl:when test="(count(preceding::*) mod  2) = 0">#ada96e</xsl:when>
-          <xsl:otherwise>gray</xsl:otherwise>
+          <xsl:otherwise>silver</xsl:otherwise>
         </xsl:choose>
         <xsl:text>;width:</xsl:text>
         <xsl:call-template name="percent">
@@ -217,9 +290,9 @@
       <xsl:attribute name="title">
         <xsl:value-of select="@name"/>
         <xsl:text>: km </xsl:text>
-        <xsl:value-of select="@from"/>
+        <xsl:value-of select="format-number(@from, $km-pattern, $locale)"/>
         <xsl:text> - </xsl:text>
-        <xsl:value-of select="@to"/>
+        <xsl:value-of select="format-number(@to, $km-pattern, $locale)"/>
       </xsl:attribute>
       <nobr><xsl:value-of select="@name"/></nobr>
     </div>
@@ -240,7 +313,7 @@
           <th>&#160;</th>
         </xsl:if>
         <th><xsl:apply-templates mode="gauges" select="/fixings/gauges"/></th>
-        <th>Ereignis</th>
+        <th><xsl:value-of select="$i18n-event"/></th>
       </tr>
       <xsl:apply-templates/>
     </table>
@@ -250,36 +323,36 @@
     <xsl:apply-templates/>
     <hr/>
     <table border="1" cellspacing="0" cellpadding="0">
-      <caption>Legende</caption>
+      <caption><xsl:value-of select="$i18n-legend"/></caption>
       <tr>
-        <th>Farbe</th>
-        <th colspan="2">Bedeutung</th>
+        <th><xsl:value-of select="$i18n-color"/></th>
+        <th colspan="2"><xsl:value-of select="$i18n-meaning"/></th>
       </tr>
       <xsl:if test="count(/fixings/events/event/sector[@class = '0']) &gt; 0">
       <tr>
         <td style="background: green">&#160;</td>
-        <td>um MNQ</td>
+        <td><xsl:value-of select="$i18n-around-mnq"/></td>
         <td>Q &#8712; [0, (MNQ+MQ)/2)</td>
       </tr>
       </xsl:if>
       <xsl:if test="count(/fixings/events/event/sector[@class = '1']) &gt; 0">
       <tr>
         <td style="background: blue">&#160;</td>
-        <td>um MQ</td>
+        <td><xsl:value-of select="$i18n-around-mq"/></td>
         <td>Q &#8712; [(MNQ+MQ)/2, (MQ+MHQ)/2)</td>
       </tr>
       </xsl:if>
       <xsl:if test="count(/fixings/events/event/sector[@class = '2']) &gt; 0">
       <tr>
         <td style="background: magenta">&#160;</td>
-        <td>um MHQ</td>
+        <td><xsl:value-of select="$i18n-around-mhq"/></td>
         <td>Q &#8712; [(MQ+MHQ)/2, HQ5)</td>
       </tr>
       </xsl:if>
       <xsl:if test="count(/fixings/events/event/sector[@class = '3']) &gt; 0">
       <tr>
         <td style="background: red">&#160;</td>
-        <td>über HQ5</td>
+        <td><xsl:value-of select="$i18n-above-hq5"/></td>
         <td>Q &#8712; [HQ5, &#8734;)</td>
       </tr>
       </xsl:if>

http://dive4elements.wald.intevation.org