[sword-svn] r198 - in trunk: . WEB-INF/lib admin examples src
src/org src/org/crosswire src/org/crosswire/web
src/org/crosswire/web/i18n
scribe at crosswire.org
scribe at crosswire.org
Wed Mar 30 12:57:02 MST 2005
Author: scribe
Date: 2005-03-30 12:57:01 -0700 (Wed, 30 Mar 2005)
New Revision: 198
Added:
trunk/WEB-INF/lib/crosswire-i18n.tld
trunk/admin/
trunk/admin/translate.jsp
trunk/examples/transtest.jsp
trunk/src/
trunk/src/Makefile
trunk/src/org/
trunk/src/org/crosswire/
trunk/src/org/crosswire/web/
trunk/src/org/crosswire/web/i18n/
trunk/src/org/crosswire/web/i18n/ContextStart.java.notyet
trunk/src/org/crosswire/web/i18n/PageStart.java
trunk/src/org/crosswire/web/i18n/TranslateTag.java
Log:
Added glasseyes i18n taglib and a basic facility for online collaborative
translation work.
Added: trunk/WEB-INF/lib/crosswire-i18n.tld
===================================================================
--- trunk/WEB-INF/lib/crosswire-i18n.tld 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/WEB-INF/lib/crosswire-i18n.tld 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
+<taglib>
+ <tlibversion>1.0</tlibversion>
+ <jspversion>1.1</jspversion>
+ <shortname>i18n</shortname>
+ <uri>http://www.crosswire.org/swordweb/i18n-1.0</uri>
+ <info>
+The i18n custom tag library contains tags that help manage the complexity of creating internationalized web applications. These tags provide similar (though not identical) functionality to the internationalization available in the struts framework, but do not require adopting the entire struts framework.
+
+"i18n" is a common abbreviation for internationalization, because there are 18
+letters between the first "i" and the last "n".
+
+For more information on internationalization with Java, the java.sun.com site
+contains a good
+tutorial written by Dale Green.
+</info>
+ <tag>
+ <name>pagestart</name>
+ <tagclass>org.crosswire.web.i18n.PageStart</tagclass>
+ <bodycontent>JSP</bodycontent>
+ </tag>
+ <tag>
+ <name>t</name>
+ <tagclass>org.crosswire.web.i18n.TranslateTag</tagclass>
+ <bodycontent>JSP</bodycontent>
+ </tag>
+</taglib>
+
+
+
+
+
+
+
Added: trunk/admin/translate.jsp
===================================================================
--- trunk/admin/translate.jsp 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/admin/translate.jsp 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,63 @@
+<%@ page import="java.util.Vector" %>
+<%@ page import="java.util.Properties" %>
+<%@ page import="java.io.File" %>
+<%@ page import="java.io.FileOutputStream" %>
+<%@ page import="org.crosswire.web.i18n.*" %>
+
+<html>
+<body>
+<%
+ Vector pageTags = (Vector)session.getAttribute("pageTags");
+ if (pageTags != null) {
+
+
+ if (request.getParameter("t0") != null) {
+ Properties locale = TranslateTag.getSessionLocale(pageContext);
+ for (int i = 0; i < pageTags.size(); i++) {
+ String key = (String)pageTags.get(i);
+ String value = (String)request.getParameter("t"+Integer.toString(i));
+ if ((key != null) && (value != null)) {
+ locale.setProperty(""+key.hashCode(), value);
+ }
+ }
+
+ String localeName = (String)session.getAttribute("lang");
+ File propName = new File(pageContext.getServletContext().getRealPath("/WEB-INF/classes/trans_"+localeName+".properties"));
+ FileOutputStream propFile = new FileOutputStream(propName);
+ locale.store(propFile, null);
+ propFile.close();
+ }
+
+ String requestURL = (String)session.getAttribute("requestURL");
+
+%>
+<p><a href="<%=requestURL%>">Return to website</a></p>
+<p>Strings which are marked for translation:</p>
+ <form action="translate.jsp?action=save">
+ <fieldset>
+<%
+ for (int i = 0; i < pageTags.size(); i++) {
+ String key = (String)pageTags.get(i);
+ String value = TranslateTag.getTranslation(pageContext, key, false);
+%>
+ <legend><%= key %></legend>
+ <input type="text" name="t<%=i%>" size="100" value="<%=value%>"/>
+ <br/>
+<%
+ }
+%>
+ <input type="submit" value="go" title="Search by keyword or phrase" />
+ </fieldset>
+ </form>
+<%
+ }
+ else {
+%>
+
+<p>No strings which are marked for translation.</p>
+<p><a href="<%= session.getAttribute("requestURL") %>">Return to website</a></p>
+<%
+ }
+%>
+</body>
+</html>
Added: trunk/examples/transtest.jsp
===================================================================
--- trunk/examples/transtest.jsp 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/examples/transtest.jsp 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,17 @@
+<%@ taglib uri="/WEB-INF/lib/crosswire-i18n.tld" prefix="t" %>
+<%
+ String lang = request.getParameter("lang");
+ if (lang != null)
+ session.setAttribute("lang", lang);
+%>
+<html>
+<body>
+<t:pagestart/>
+below is translated text<br/>
+<t:t>Translate this text</t:t><br/>
+<t:t>Translate text 2</t:t>
+
+<br/><br/>
+<a href="translate.jsp">Translate this page</a>
+</body>
+</html>
Added: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/src/Makefile 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,9 @@
+TOMCAT_HOME=/usr/local/tomcat
+instdir=..
+all: ../WEB-INF/classes/org/crosswire/web/i18n/TranslateTag.class
+
+../WEB-INF/classes/org/crosswire/web/i18n/TranslateTag.class: org/crosswire/web/i18n/TranslateTag.java
+ javac -classpath ${TOMCAT_HOME}/common/lib/jsp-api.jar:${TOMCAT_HOME}/common/lib/servlet-api.jar -d ../WEB-INF/classes -sourcepath . ./org/crosswire/web/i18n/*.java
+
+clean:
+ rm -rf ../WEB-INF/classes/org/crosswire/web/*
Added: trunk/src/org/crosswire/web/i18n/ContextStart.java.notyet
===================================================================
--- trunk/src/org/crosswire/web/i18n/ContextStart.java.notyet 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/src/org/crosswire/web/i18n/ContextStart.java.notyet 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,10 @@
+package org.crosswire.web.i18n;
+
+import javax.servlet.jsp.tagext.*;
+
+public class ContextStart extends TagSupport {
+
+ public ContextStart() {
+ }
+
+}
Added: trunk/src/org/crosswire/web/i18n/PageStart.java
===================================================================
--- trunk/src/org/crosswire/web/i18n/PageStart.java 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/src/org/crosswire/web/i18n/PageStart.java 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,28 @@
+package org.crosswire.web.i18n;
+
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Vector;
+
+
+public class PageStart extends BodyTagSupport {
+
+ public int doEndTag() throws JspException {
+ try {
+ HttpSession session = pageContext.getSession();
+ session.setAttribute("pageTags", new Vector());
+ try {
+ session.setAttribute("requestURL", ((HttpServletRequest)pageContext.getRequest()).getRequestURI());
+ }
+ catch (Exception e1) {}
+ }
+ catch(Exception e) {
+ throw new JspTagException("IO Error: " + e.getMessage());
+ }
+ return EVAL_PAGE;
+ }
+}
Added: trunk/src/org/crosswire/web/i18n/TranslateTag.java
===================================================================
--- trunk/src/org/crosswire/web/i18n/TranslateTag.java 2005-03-16 00:58:00 UTC (rev 197)
+++ trunk/src/org/crosswire/web/i18n/TranslateTag.java 2005-03-30 19:57:01 UTC (rev 198)
@@ -0,0 +1,94 @@
+package org.crosswire.web.i18n;
+
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.PageContext;
+import java.util.Vector;
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+
+public class TranslateTag extends BodyTagSupport {
+
+
+ private String bodyText = "";
+
+ public static Properties getSessionLocale(PageContext pageContext) {
+ HttpSession session = pageContext.getSession();
+ Properties locale = null;
+ try {
+ String localeName = (String)session.getAttribute("lang");
+ if (localeName == null) localeName = "en_US";
+ locale = (Properties)session.getAttribute("locale_"+localeName);
+ if (locale == null) {
+ locale = new Properties();
+ File propName = new File(pageContext.getServletContext().getRealPath("/WEB-INF/classes/trans_"+localeName+".properties"));
+ if (propName.exists()) {
+ FileInputStream propFile = new FileInputStream(propName);
+ locale.load(propFile);
+ propFile.close();
+ }
+ session.setAttribute("locale_"+localeName, locale);
+ }
+ }
+ catch (Exception e) { e.printStackTrace(); }
+
+ return locale;
+ }
+
+
+ public static String getTranslation(PageContext pageContext, String english, boolean addPageTag) throws JspTagException {
+ String hashkey = "" + english.hashCode();
+ String result = english;
+ try {
+ HttpSession session = pageContext.getSession();
+ Vector pageTags = (Vector)session.getAttribute("pageTags");
+ if (addPageTag) {
+ if (pageTags == null) {
+ pageTags = new Vector();
+ session.setAttribute("pageTags", pageTags);
+ }
+ pageTags.add(english);
+ }
+ Properties locale = getSessionLocale(pageContext);
+ result = locale.getProperty(hashkey);
+ if (result == null) {
+ // do we need to do this?
+ String localeName = (String)session.getAttribute("lang");
+ locale.setProperty(hashkey, ("en_US".equals(localeName))?english:"");
+ File propName = new File(pageContext.getServletContext().getRealPath("/WEB-INF/classes/trans_"+localeName+".properties"));
+ FileOutputStream propFile = new FileOutputStream(propName);
+ locale.store(propFile, null);
+ propFile.close();
+ // ---------------------
+ result = english;
+ }
+ if (result.length() < 1) {
+ result = english;
+ }
+ }
+ catch (Exception e) { e.printStackTrace(); }
+ return result;
+ }
+
+ public int doAfterBody() throws JspTagException {
+ BodyContent bc = getBodyContent();
+ bodyText = bc.getString();
+ return 0;
+ }
+
+ public int doEndTag() throws JspException {
+ try {
+ pageContext.getOut().write(getTranslation(pageContext, bodyText, true));
+ }
+ catch(Exception e) {
+ throw new JspTagException("IO Error: " + e.getMessage());
+ }
+ return EVAL_PAGE;
+ }
+}
More information about the sword-cvs
mailing list