From 9af796a10a949ee0d21f1d96c87b67ce3dcd4bf5 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 10 Dec 2009 01:06:55 +0000 Subject: [PATCH] translation support --- apps/i2ptunnel/java/bmsg.sh | 17 ++++ apps/i2ptunnel/java/build.xml | 41 ++++++++- apps/i2ptunnel/java/bundle-messages.bat | 26 ++++++ apps/i2ptunnel/java/bundle-messages.sh | 88 +++++++++++++++++++ .../src/net/i2p/i2ptunnel/web/Messages.java | 37 ++++++++ apps/i2ptunnel/jsp/editClient.jsp | 3 +- apps/i2ptunnel/jsp/editServer.jsp | 3 +- apps/i2ptunnel/jsp/index.jsp | 3 +- apps/i2ptunnel/locale/messages_de.po | 30 +++++++ build.xml | 1 + 10 files changed, 242 insertions(+), 7 deletions(-) create mode 100644 apps/i2ptunnel/java/bmsg.sh create mode 100644 apps/i2ptunnel/java/bundle-messages.bat create mode 100755 apps/i2ptunnel/java/bundle-messages.sh create mode 100644 apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/Messages.java create mode 100644 apps/i2ptunnel/locale/messages_de.po diff --git a/apps/i2ptunnel/java/bmsg.sh b/apps/i2ptunnel/java/bmsg.sh new file mode 100644 index 000000000..b9d294b32 --- /dev/null +++ b/apps/i2ptunnel/java/bmsg.sh @@ -0,0 +1,17 @@ +# +# Update messages_xx.po and messages_xx.class files, +# from both java and jsp sources. +# Requires installed programs xgettext, msgfmt, msgmerge, and find. +# zzz - public domain +# + +## launching sh.exe with -login parameter will open a shell with the current path always pointing to \bin\ +## need to cd into our orignal path - where we call sh.exe from. + +cd $CALLFROM +## echo $PWD + +## except this everything is the same with bundle-message.sh +## walking - public domain :-D + +source bundle-messages.sh $PARAS \ No newline at end of file diff --git a/apps/i2ptunnel/java/build.xml b/apps/i2ptunnel/java/build.xml index a74e328cc..fa3e5d677 100644 --- a/apps/i2ptunnel/java/build.xml +++ b/apps/i2ptunnel/java/build.xml @@ -42,12 +42,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -113,11 +150,7 @@ - - - - diff --git a/apps/i2ptunnel/java/bundle-messages.bat b/apps/i2ptunnel/java/bundle-messages.bat new file mode 100644 index 000000000..90feca972 --- /dev/null +++ b/apps/i2ptunnel/java/bundle-messages.bat @@ -0,0 +1,26 @@ +@echo off +set Callfrom=%cd% +set Paras=%1 + +rem before calling make sure you have msys and mingw 's "bin" path +rem in your current searching path +rem type "set path" to check +if not exist ..\locale\*.only goto updateALL + +rem put a messages_xx.only(eg messages_zh.only) into locale folder +rem this script will only touch the po file(eg zh) you specified, leaving other po files untact. + +for %%i in (..\locale\*.only) do set PO=%%~ni +echo [Notice] Yu choose to Ony update the choosen file: %PO%.po +for %%i in (..\locale\*.po) do if not %%~ni==%PO% ren %%i %%~ni.po- + +call sh --login %cd%\bmsg.sh + +for %%i in (..\locale\*.po-) do if not %%~ni==%PO% ren %%i %%~ni.po +goto end + +:updateALL +call sh --login %cd%\bmsg.sh + +:end +echo End of Message Bundling \ No newline at end of file diff --git a/apps/i2ptunnel/java/bundle-messages.sh b/apps/i2ptunnel/java/bundle-messages.sh new file mode 100755 index 000000000..b4f694b71 --- /dev/null +++ b/apps/i2ptunnel/java/bundle-messages.sh @@ -0,0 +1,88 @@ +# +# Update messages_xx.po and messages_xx.class files, +# from both java and jsp sources. +# Requires installed programs xgettext, msgfmt, msgmerge, and find. +# +# usage: +# bundle-messages.sh (generates the resource bundle from the .po file) +# bundle-messages.sh -p (updates the .po file from the source tags, then generates the resource bundle) +# +# zzz - public domain +# +CLASS=net.i2p.i2ptunnel.web.messages +TMPFILE=build/javafiles.txt +export TZ=UTC + +if [ "$1" = "-p" ] +then + POUPDATE=1 +fi + +# add ../java/ so the refs will work in the po file +JPATHS="../java/src ../jsp/WEB-INF" +for i in ../locale/messages_*.po +do + # get language + LG=${i#../locale/messages_} + LG=${LG%.po} + + if [ "$POUPDATE" = "1" ] + then + # make list of java files newer than the .po file + find $JPATHS -name *.java -newer $i > $TMPFILE + fi + + if [ -s build/obj/net/i2p/i2ptunnel/messages_$LG.class -a \ + build/obj/net/i2p/i2ptunnel/messages_$LG.class -nt $i -a \ + ! -s $TMPFILE ] + then + continue + fi + + if [ "$POUPDATE" = "1" ] + then + echo "Updating the $i file from the tags..." + # extract strings from java and jsp files, and update messages.po files + # translate calls must be one of the forms: + # _("foo") + # _x("foo") + # intl._("foo") + # intl.title("foo") + # In a jsp, you must use a helper or handler that has the context set. + # To start a new translation, copy the header from an old translation to the new .po file, + # then ant distclean updater. + find $JPATHS -name *.java > $TMPFILE + xgettext -f $TMPFILE -F -L java --from-code=UTF-8 \ + --keyword=_ --keyword=_x --keyword=intl._ --keyword=intl.title \ + -o ${i}t + if [ $? -ne 0 ] + then + echo 'Warning - xgettext failed, not updating translations' + rm -f ${i}t + break + fi + msgmerge -U --backup=none $i ${i}t + if [ $? -ne 0 ] + then + echo 'Warning - msgmerge failed, not updating translations' + rm -f ${i}t + break + fi + rm -f ${i}t + # so we don't do this again + touch $i + fi + + echo "Generating ${CLASS}_$LG ResourceBundle..." + + # convert to class files in build/obj + msgfmt --java -r $CLASS -l $LG -d build/obj $i + if [ $? -ne 0 ] + then + echo 'Warning - msgfmt failed, not updating translations' + break + fi +done +rm -f $TMPFILE +# todo: return failure +exit 0 diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/Messages.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/Messages.java new file mode 100644 index 000000000..fa3839232 --- /dev/null +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/Messages.java @@ -0,0 +1,37 @@ +package net.i2p.i2ptunnel.web; + +import net.i2p.I2PAppContext; +import net.i2p.util.Translate; + +/** + * Translate strings for this package. + */ +public class Messages { + private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.messages"; + private final I2PAppContext _context; + + public Messages() { + _context = I2PAppContext.getGlobalContext(); + } + + /** lang in routerconsole.lang property, else current locale */ + public String _(String key) { + return Translate.getString(key, _context, BUNDLE_NAME); + } + + /** + * 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 String _(String s, Object o) { + return Translate.getString(s, o, _context, BUNDLE_NAME); + } +} diff --git a/apps/i2ptunnel/jsp/editClient.jsp b/apps/i2ptunnel/jsp/editClient.jsp index 67452919d..40d1028b0 100644 --- a/apps/i2ptunnel/jsp/editClient.jsp +++ b/apps/i2ptunnel/jsp/editClient.jsp @@ -1,6 +1,7 @@ <%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean"%> + <% String tun = request.getParameter("tunnel"); int curTunnel = -1; if (tun != null) { @@ -13,7 +14,7 @@ %> - I2P Tunnel Manager - Edit + <%=intl._("I2P Tunnel Manager - Edit Client Tunnel")%> diff --git a/apps/i2ptunnel/jsp/editServer.jsp b/apps/i2ptunnel/jsp/editServer.jsp index 610b68a51..da98470f7 100644 --- a/apps/i2ptunnel/jsp/editServer.jsp +++ b/apps/i2ptunnel/jsp/editServer.jsp @@ -1,6 +1,7 @@ <%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean"%> + <% String tun = request.getParameter("tunnel"); int curTunnel = -1; if (tun != null) { @@ -13,7 +14,7 @@ %> - I2P Tunnel Manager - Edit + <%=intl._("I2P Tunnel Manager - Edit Server Tunnel")%> diff --git a/apps/i2ptunnel/jsp/index.jsp b/apps/i2ptunnel/jsp/index.jsp index 87a006f6d..6c2f7f73e 100644 --- a/apps/i2ptunnel/jsp/index.jsp +++ b/apps/i2ptunnel/jsp/index.jsp @@ -8,9 +8,10 @@ + - I2P Tunnel Manager - List + <%=intl._("I2P Tunnel Manager - List")%> diff --git a/apps/i2ptunnel/locale/messages_de.po b/apps/i2ptunnel/locale/messages_de.po new file mode 100644 index 000000000..3862132a9 --- /dev/null +++ b/apps/i2ptunnel/locale/messages_de.po @@ -0,0 +1,30 @@ +# I2P +# Copyright (C) 2009 The I2P Project +# This file is distributed under the same license as the i2ptunnel package. +# To contribute translations, see http://www.i2p2.de/newdevelopers +# foo , 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: I2P i2ptunnel\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-12-10 00:50+0000\n" +"PO-Revision-Date: 2009-10-19 12:50+0000\n" +"Last-Translator: foo \n" +"Language-Team: foo \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Language: German\n" + +#: ../jsp/WEB-INF/classes/net/i2p/i2ptunnel/jsp/editClient_jsp.java:73 +msgid "I2P Tunnel Manager - Edit Client Tunnel" +msgstr "" + +#: ../jsp/WEB-INF/classes/net/i2p/i2ptunnel/jsp/editServer_jsp.java:73 +msgid "I2P Tunnel Manager - Edit Server Tunnel" +msgstr "" + +#: ../jsp/WEB-INF/classes/net/i2p/i2ptunnel/jsp/index_jsp.java:71 +msgid "I2P Tunnel Manager - List" +msgstr "" diff --git a/build.xml b/build.xml index 961fe3dea..13de3a1b4 100644 --- a/build.xml +++ b/build.xml @@ -142,6 +142,7 @@ +