forked from I2P_Developers/i2p.i2p
* Translations:
- New varargs method in Translate - New TranslateReader to translate static files on-the-fly using _("") tagging - Tag proxy error pages for TranslateReader - Drop static translated proxy error pages - Add new i2ptunnel bundle for the proxy alone, shipped in the jar - Use TranslateReader in HTTP proxy for error pages - Move HTTP proxy strings from the web *war) to proxy (jar) bundle so they will be loaded - Initial translations created by msgmerge from i2ptunnel and routerconsole po files, un-fuzzied
This commit is contained in:
@@ -56,7 +56,7 @@
|
||||
|
||||
|
||||
<!-- The web classes are now in the war not the jar - they are not part of the API -->
|
||||
<target name="jar" depends="builddep, compile, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
|
||||
<target name="jar" depends="builddep, compile, bundle-proxy, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
|
||||
<!-- set if unset -->
|
||||
<property name="workspace.changes.j.tr" value="" />
|
||||
<jar destfile="./build/i2ptunnel.jar" basedir="./build/obj" includes="**/*.class" excludes="**/EditBean.class **/IndexBean.class" >
|
||||
@@ -87,6 +87,7 @@
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
<!-- servlet translations go in the war, not the jar -->
|
||||
<target name="bundle" depends="compile, precompilejsp" unless="no.bundle">
|
||||
<!-- Update the messages_*.po files.
|
||||
We need to supply the bat file for windows, and then change the fail property to true -->
|
||||
@@ -118,6 +119,49 @@
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<!-- proxy error page translations go in the jar, not the war -->
|
||||
<target name="bundle-proxy" unless="no.bundle">
|
||||
<!-- Update the messages_*.po files.
|
||||
We need to supply the bat file for windows, and then change the fail property to true -->
|
||||
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="${require.gettext}" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
</exec>
|
||||
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="${require.gettext}" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
</exec>
|
||||
<!-- multi-lang is optional -->
|
||||
<exec executable="sh" osfamily="windows" failifexecutionfails="false" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="extractProxyTags">
|
||||
<java classname="net.i2p.util.TranslateReader" fork="true" failonerror="true">
|
||||
<classpath>
|
||||
<pathelement location="../../../build/i2p.jar" />
|
||||
</classpath>
|
||||
<arg value="tag" />
|
||||
<arg value="../../../installer/resources/proxy/" />
|
||||
<arg value="build/Proxy.java" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="poupdate-proxy" depends="extractProxyTags">
|
||||
<!-- Update the messages_*.po files. -->
|
||||
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="true" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
<arg value="-p" />
|
||||
</exec>
|
||||
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="true" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
<arg value="-p" />
|
||||
</exec>
|
||||
<exec executable="sh" osfamily="windows" failifexecutionfails="true" failonerror="true" >
|
||||
<arg value="./bundle-messages-proxy.sh" />
|
||||
<arg value="-p" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="listChangedFiles2" depends="warUpToDate" if="shouldListChanges2" >
|
||||
<exec executable="mtn" outputproperty="workspace.changes.w" errorproperty="mtn.error2" failifexecutionfails="false" >
|
||||
<arg value="list" />
|
||||
|
110
apps/i2ptunnel/java/bundle-messages-proxy.sh
Executable file
110
apps/i2ptunnel/java/bundle-messages-proxy.sh
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 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.proxy.messages
|
||||
TMPFILE=build/javafiles-proxy.txt
|
||||
export TZ=UTC
|
||||
RC=0
|
||||
|
||||
if [ "$1" = "-p" ]
|
||||
then
|
||||
POUPDATE=1
|
||||
fi
|
||||
|
||||
# on windows, one must specify the path of commnad find
|
||||
# since windows has its own retarded version of find.
|
||||
if which find|grep -q -i windows ; then
|
||||
export PATH=.:/bin:/usr/local/bin:$PATH
|
||||
fi
|
||||
# Fast mode - update ondemond
|
||||
# set LG2 to the language you need in envrionment varibales to enable this
|
||||
|
||||
# add ../java/ so the refs will work in the po file
|
||||
JPATHS="../java/build/Proxy.java ../java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java ../java/src/net/i2p/i2ptunnel/localServer/LocalHTTPServer.java"
|
||||
for i in ../locale-proxy/messages_*.po
|
||||
do
|
||||
# get language
|
||||
LG=${i#../locale-proxy/messages_}
|
||||
LG=${LG%.po}
|
||||
|
||||
# skip, if specified
|
||||
if [ $LG2 ]; then
|
||||
[ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
|
||||
fi
|
||||
|
||||
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/proxy/messages_$LG.class -a \
|
||||
build/obj/net/i2p/i2ptunnel/proxy/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 --add-comments\
|
||||
--keyword=_ \
|
||||
-o ${i}t
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "ERROR - xgettext failed on ${i}, not updating translations"
|
||||
rm -f ${i}t
|
||||
RC=1
|
||||
break
|
||||
fi
|
||||
msgmerge -U --backup=none $i ${i}t
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "ERROR - msgmerge failed on ${i}, not updating translations"
|
||||
rm -f ${i}t
|
||||
RC=1
|
||||
break
|
||||
fi
|
||||
rm -f ${i}t
|
||||
# so we don't do this again
|
||||
touch $i
|
||||
fi
|
||||
|
||||
if [ "$LG" != "en" ]
|
||||
then
|
||||
# only generate for non-source language
|
||||
echo "Generating ${CLASS}_$LG ResourceBundle..."
|
||||
|
||||
# convert to class files in build/obj
|
||||
msgfmt --java --statistics -r $CLASS -l $LG -d build/obj $i
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "ERROR - msgfmt failed on ${i}, not updating translations"
|
||||
# msgfmt leaves the class file there so the build would work the next time
|
||||
find build/obj -name messages_${LG}.class -exec rm -f {} \;
|
||||
RC=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
rm -f $TMPFILE
|
||||
exit $RC
|
@@ -29,7 +29,7 @@ fi
|
||||
# set LG2 to the language you need in envrionment varibales to enable this
|
||||
|
||||
# add ../java/ so the refs will work in the po file
|
||||
JPATHS="../java/src ../jsp/WEB-INF"
|
||||
JPATHS="../java/src/net/i2p/i2ptunnel/web ../jsp/WEB-INF"
|
||||
for i in ../locale/messages_*.po
|
||||
do
|
||||
# get language
|
||||
|
@@ -1409,8 +1409,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
||||
}
|
||||
}
|
||||
****/
|
||||
/** */
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.web.messages";
|
||||
|
||||
/** these strings go in the jar, not the war */
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.proxy.messages";
|
||||
|
||||
/** lang in routerconsole.lang property, else current locale */
|
||||
protected static String _(String key) {
|
||||
|
@@ -3,9 +3,9 @@
|
||||
*/
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,6 +27,7 @@ import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.InternalSocket;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.PasswordManager;
|
||||
import net.i2p.util.TranslateReader;
|
||||
|
||||
/**
|
||||
* Common things for HTTPClient and ConnectClient
|
||||
@@ -496,44 +497,35 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
*/
|
||||
protected static byte[] getErrorPage(I2PAppContext ctx, String base, byte[] backup) {
|
||||
File errorDir = new File(ctx.getBaseDir(), "docs");
|
||||
String lang = ctx.getProperty("routerconsole.lang", Locale.getDefault().getLanguage());
|
||||
if(lang != null && lang.length() > 0 && !lang.equals("en")) {
|
||||
File file = new File(errorDir, base + "-header_" + lang + ".ht");
|
||||
try {
|
||||
return readFile(file);
|
||||
} catch(IOException ioe) {
|
||||
// try the english version now
|
||||
}
|
||||
}
|
||||
File file = new File(errorDir, base + "-header.ht");
|
||||
try {
|
||||
return readFile(file);
|
||||
return readFile(ctx, file);
|
||||
} catch(IOException ioe) {
|
||||
return backup;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.proxy.messages";
|
||||
|
||||
/**
|
||||
* @since 0.9.4 moved from I2PTunnelHTTPClient
|
||||
*/
|
||||
private static byte[] readFile(File file) throws IOException {
|
||||
FileInputStream fis = null;
|
||||
byte[] buf = new byte[2048];
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
|
||||
private static byte[] readFile(I2PAppContext ctx, File file) throws IOException {
|
||||
Reader reader = null;
|
||||
char[] buf = new char[512];
|
||||
StringBuilder out = new StringBuilder(2048);
|
||||
try {
|
||||
int len = 0;
|
||||
fis = new FileInputStream(file);
|
||||
while((len = fis.read(buf)) > 0) {
|
||||
baos.write(buf, 0, len);
|
||||
int len;
|
||||
reader = new TranslateReader(ctx, BUNDLE_NAME, new FileInputStream(file));
|
||||
while((len = reader.read(buf)) > 0) {
|
||||
out.append(buf, 0, len);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
return out.toString().getBytes("UTF-8");
|
||||
} finally {
|
||||
try {
|
||||
if(fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
} catch(IOException foo) {
|
||||
}
|
||||
if(reader != null)
|
||||
reader.close();
|
||||
} catch(IOException foo) {}
|
||||
}
|
||||
// we won't ever get here
|
||||
}
|
||||
|
@@ -233,7 +233,8 @@ public abstract class LocalHTTPServer {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.web.messages";
|
||||
/** these strings go in the jar, not the war */
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.proxy.messages";
|
||||
|
||||
/** lang in routerconsole.lang property, else current locale */
|
||||
protected static String _(String key) {
|
||||
|
Reference in New Issue
Block a user