Author: fred
Date: 2007-07-20 21:42:03 +0000 (Fri, 20 Jul 2007)
New Revision: 14216
Added:
trunk/plugins/Echo/src/plugins/echo/i18n/
trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.fr.properties
Modified:
trunk/plugins/Echo/src/plugins/echo/Echo.java
trunk/plugins/Echo/src/plugins/echo/NodesManager.java
trunk/plugins/Echo/src/xml/edit.xsl
Log:
Add Internationalization support
Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-07-20 19:37:46 UTC
(rev 14215)
+++ trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-07-20 21:42:03 UTC
(rev 14216)
@@ -1,5 +1,7 @@
package plugins.echo;
+import plugins.echo.i18n.I18n;
+
import freenet.pluginmanager.FredPlugin;
import freenet.pluginmanager.FredPluginHTTP;
import freenet.pluginmanager.FredPluginHTTPAdvanced;
@@ -51,6 +53,7 @@
private PluginRespirator respirator;
private Builder parser;
private XSLTransform transform;
+ private I18n i18n;
private Page page;
private NodesManager nodesManager;
private Node node;
@@ -58,12 +61,15 @@
public Echo() throws PluginHTTPException
{
try {
+ i18n = new I18n("en");
// suxx
NODES_DIR.mkdirs();
- System.err.println("Bleh");
parser = new Builder();
+
// Document styleSheet =
parser.build(getClass().getResourceAsStream("/xml/edit.xsl"));
Document styleSheet =
parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/edit.xsl");
+ i18n.translateXML(styleSheet);
+
transform = new XSLTransform(styleSheet);
transform.setParameter("contextprefix",
NODES_DIR.getAbsolutePath() + "/");
@@ -155,11 +161,9 @@
node = nodesManager.getNodeById(nodeId);
if(node == null)
page.appendError("The node " +
nodeId + "does not exist");
- else {
+ else
page.appendData(node.getRoot());
- // DEBUG
-
System.err.println("node.getRoot() : '" + node.getRoot().toXML() +"'");
- }
+
} catch (IOException ioe) {
page.appendError(ioe.getMessage());
} catch (ParsingException pe) {
@@ -238,11 +242,8 @@
setDefaultPage();
}
-
- // DEBUG
-// System.out.println("Page : '" + page.getDoc().toXML() + "'");
+
return transform(page);
-
}
public String handleHTTPPut(HTTPRequest request) throws
PluginHTTPException {
Modified: trunk/plugins/Echo/src/plugins/echo/NodesManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-07-20
19:37:46 UTC (rev 14215)
+++ trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-07-20
21:42:03 UTC (rev 14216)
@@ -221,7 +221,6 @@
serializer.setIndent(4);
serializer.setMaxLength(128);
serializer.write(new Document(cats));
- System.err.println("Manager.categories.size : " +
categories.size());
}
}
Added: trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
(rev 0)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java 2007-07-20 21:42:03 UTC
(rev 14216)
@@ -0,0 +1,70 @@
+package plugins.echo.i18n;
+
+import java.util.Properties;
+import java.io.FileInputStream; // DEBUG
+
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+import nu.xom.Nodes;
+import nu.xom.Element;
+import nu.xom.Text;
+import nu.xom.Document;
+
+/**
+* This class provides a trivial internationalization framework
+*/
+public class I18n {
+
+ public static final String[] AVAILABLE_LANGUAGES = { "en", "fr" };
+
+ private Properties translation;
+
+ public I18n(String language) throws FileNotFoundException, IOException {
+
+ translation = new Properties();
+ setLanguage(language);
+
+ }
+
+ /**
+ * Set the language
+ * @param language the ISO code of the language
+ */
+ public void setLanguage(String language) throws FileNotFoundException,
IOException {
+
+ // TODO : getRessourceAsStream()
+ translation.load(new
FileInputStream("/home/fred/prog/soc/trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n."
+ language + ".properties"));
+
+ }
+
+ /**
+ * Return the translation of the key
+ * @param key
+ * @return the translated String or null if the key dont exists
+ */
+ public String getString(String key) {
+
+ return translation.getProperty(key);
+
+ }
+
+ /**
+ * Translate a whole XML document, replace i18n elements by the
translations of their keys
+ * @param doc the nu.xom.Document to translate
+ */
+ public void translateXML(Document doc) {
+
+ nu.xom.Nodes i18nNodes = doc.query("//i18n");
+
+ for(int i=0; i < i18nNodes.size(); i++) {
+
+ String key = ((Element)
i18nNodes.get(i)).getAttributeValue("key");
+ String translatedKey = getString(key);
+
+
i18nNodes.get(i).getParent().replaceChild(i18nNodes.get(i), new
Text(translatedKey));
+ }
+ }
+
+
+}
\ No newline at end of file
Added: trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
(rev 0)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
2007-07-20 21:42:03 UTC (rev 14216)
@@ -0,0 +1,25 @@
+
+echo.action.write=Write
+echo.action.manage=Manage
+echo.action.publish=Publish
+
+echo.common.blogPost=Blog post
+echo.common.staticPage=Static page
+echo.common.categories=Categories
+echo.common.name=Name
+echo.common.action=Action
+echo.common.edit=Edit
+echo.common.rename=Rename
+echo.common.delete=Delete
+echo.common.date=Date
+echo.common.title=Title
+echo.common.nodeType=Type
+
+echo.write.newPost=Create a new post
+echo.write.newPage=Create a new page
+echo.write.nodeBody=Body
+
+echo.manage.myNodes=My nodes
+echo.manage.myNodes.desc=A list of your nodes
+echo.manage.newCategory=New category
+echo.manage.categories.desc=Categorize your posts
\ No newline at end of file
Added: trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.fr.properties
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.fr.properties
(rev 0)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.fr.properties
2007-07-20 21:42:03 UTC (rev 14216)
@@ -0,0 +1,25 @@
+
+echo.action.write=Ecrire
+echo.action.manage=Organiser
+echo.action.publish=Publier
+
+echo.common.blogPost=Billet
+echo.common.staticPage=Page statique
+echo.common.categories=Cat?gories
+echo.common.name=Nom
+echo.common.action=Action
+echo.common.edit=Editer
+echo.common.rename=Renomer
+echo.common.delete=Supprimer
+echo.common.date=Date
+echo.common.title=Titre
+echo.common.nodeType=Type
+
+echo.write.newPost=Cr?er un nouveau billet
+echo.write.newPage=Cr?er une nouvelle page
+echo.write.nodeBody=Contenu
+
+echo.manage.myNodes=Mes noeuds
+echo.manage.myNodes.desc=Liste des noeuds
+echo.manage.newCategory=Nouvelle cat?gorie
+echo.manage.categories.desc=Organisez vos billets
\ No newline at end of file
Modified: trunk/plugins/Echo/src/xml/edit.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/edit.xsl 2007-07-20 19:37:46 UTC (rev 14215)
+++ trunk/plugins/Echo/src/xml/edit.xsl 2007-07-20 21:42:03 UTC (rev 14216)
@@ -30,9 +30,9 @@
<div id="left">
<ul id="menu">
- <li><a
href="write">Write</a></li>
- <li><a
href="manage">Manage</a></li>
- <li><a
href="publish">Publish</a></li>
+ <li><a
href="write"><i18n key="echo.action.write" /></a></li>
+ <li><a
href="manage"><i18n key="echo.action.manage" /></a></li>
+ <li><a
href="publish"><i18n key="echo.action.publish" /></a></li>
</ul>
</div>
@@ -53,22 +53,22 @@
<xsl:choose>
<xsl:when test="write">
<dl>
- <dt><a href="newPost">Blog post</a></dt>
- <dd>Create a new post</dd>
+ <dt><a href="newPost"><i18n
key="echo.common.blogPost" /></a></dt>
+ <dd><i18n key="echo.write.newPost"
/></dd>
- <dt><a href="newPage">Static
page</a></dt>
- <dd>Create a new static page.</dd>
+ <dt><a href="newPage"><i18n
key="echo.common.staticPage" /></a></dt>
+ <dd><i18n key="echo.write.newPage"
/></dd>
</dl>
</xsl:when>
<xsl:when test="manage">
<dl>
<!-- Suxx ? -->
- <dt><a href="nodes">My nodes</a></dt>
- <dd>A list of your nodes</dd>
+ <dt><a href="nodes"><i18n
key="echo.manage.myNodes" /></a></dt>
+ <dd><i18n
key="echo.manage.myNodes.desc" /></dd>
- <dt><a
href="categories">Categories</a></dt>
- <dd>Categorize your posts</dd>
+ <dt><a href="categories"><i18n
key="echo.common.categories" /></a></dt>
+ <dd><i18n
key="echo.manage.categories.desc" /></dd>
</dl>
</xsl:when>
@@ -77,8 +77,8 @@
<xsl:if
test="count(document(concat($contextprefix, '../categories.xml'))//category) >
0">
<table>
<tr>
- <th>Name</th>
- <th colspan="2">Action</th>
+ <th><i18n
key="echo.common.name" /></th>
+ <th colspan="2"><i18n
key="echo.common.action" /></th>
</tr>
<xsl:for-each
select="document(concat($contextprefix, '../categories.xml'))//category">
@@ -89,15 +89,15 @@
</xsl:if>
<td><xsl:value-of
select="text()" /></td>
- <td><a
href="renameCategory?category={@id}">Rename</a></td>
- <td><a
href="del?category={@id}">Delete</a></td>
+ <td><a
href="renameCategory?category={@id}"><i18n key="echo.common.rename" /></a></td>
+ <td><a
href="del?category={@id}"><i18n key="echo.common.delete" /></a></td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
<form name="newCategory" method="POST"
action="">
- <label for="category-name"
class="inline">New category</label>
+ <label for="category-name"
class="inline"><i18n key="echo.manage.newCategory" /></label>
<input type="text" id="category-name"
name="category-sname" class="inline" />
<input type="hidden"
name="formPassword" value="{formpassword/@value}" class="inline" />
<input type="submit" value="Create"
class="inline" />
@@ -106,7 +106,7 @@
</xsl:when>
<xsl:when test="rename">
<form name="newCategory" method="POST"
action="">
- <label for="category-name"
class="inline">Name</label>
+ <label for="category-name"
class="inline"><i18n key="echo.common.name" /></label>
<input type="text" id="category-name"
name="category-name" value="{rename/category/@name}" class="inline" />
<input type="hidden" name="category-id"
value="{rename/category/@id}" class="inline" />
<input type="hidden"
name="formPassword" value="{formpassword/@value}" class="inline" />
@@ -120,10 +120,10 @@
<table>
<tr>
<th>Id</th>
- <th>Date</th>
- <th>Title</th>
- <th>Type</th>
- <th colspan="2">Action</th>
+ <th><i18n key="echo.common.date" /></th>
+ <th><i18n key="echo.common.title"
/></th>
+ <th><i18n key="echo.common.nodeType"
/></th>
+ <th colspan="2"><i18n
key="echo.common.action" /></th>
</tr>
<xsl:for-each select="nodes/node">
<xsl:sort select="@id" />
@@ -136,8 +136,8 @@
<td><xsl:value-of
select="document(concat($contextprefix, @id, '.xml'))/node/modified" /></td>
<td><xsl:value-of
select="document(concat($contextprefix, @id, '.xml'))/node/title" /></td>
<td><xsl:value-of
select="document(concat($contextprefix, @id, '.xml'))/node/@type" /></td>
- <td><a
href="edit?node={@id}">Edit</a></td>
- <td><a
href="del?node={@id}">Delete</a></td>
+ <td><a href="edit?node={@id}"><i18n
key="echo.common.edit" /></a></td>
+ <td><a href="del?node={@id}"><i18n
key="echo.common.delete" /></a></td>
</tr>
</xsl:for-each>
</table>
@@ -150,9 +150,9 @@
<xsl:when test="./node">
<form name="edit" method="POST" action="">
- <label for="edit-title">Title</label>
+ <label for="edit-title"><i18n
key="echo.common.title" /></label>
<input type="text" id="edit-title" name="title"
value="{node/title/text()}"/>
- <label for="edit-body">Body</label>
+ <label for="edit-body"><i18n
key="echo.write.nodeBody" /></label>
<textarea id="edit-body" name="body" cols="60"
rows="20">
<xsl:choose>
<xsl:when
test="node/content/text()">
@@ -167,7 +167,7 @@
</textarea>
<xsl:if
test="count(document(concat($contextprefix,
'../categories.xml'))/categories/category) > 0">
<fieldset>
- <legend>Categories</legend>
+ <legend><i18n
key="echo.common.categories" /></legend>
<xsl:for-each
select="document(concat($contextprefix,
'../categories.xml'))/categories/category">
<input type="checkbox"
id="category-{@id}" name="category-{@id}" class="inline">
<!-- <xsl:for-each
select="node/categories/category[@id = '001']"> -->