Core: Move date/time/size translations from console to core,

so apps can use them.
Fix translation in LogWriter, was never included in console.
This commit is contained in:
zzz
2019-12-17 17:21:35 +00:00
parent d054652952
commit bf94460420
37 changed files with 3901 additions and 7 deletions

View File

@@ -5,6 +5,9 @@
<target name="builddep">
<!-- noop, since the core doesnt depend on anything -->
</target>
<condition property="no.bundle">
<isfalse value="${require.gettext}" />
</condition>
<condition property="depend.available">
<typefound name="depend" />
</condition>
@@ -100,7 +103,7 @@
</exec>
</target>
<target name="jar" depends="compile, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
<target name="jar" depends="compile, bundle, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
<!-- set if unset -->
<property name="workspace.changes.tr" value="" />
<jar destfile="./build/i2p.jar" >
@@ -132,6 +135,46 @@
</uptodate>
</target>
<target name="bundle" unless="no.bundle">
<mkdir dir="build/messages-src" />
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="${require.gettext}" >
<env key="JAVA_HOME" value="${java.home}" />
<arg value="./bundle-messages.sh" />
</exec>
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="${require.gettext}" >
<arg value="./bundle-messages.sh" />
</exec>
<exec executable="sh" osfamily="windows" failifexecutionfails="false" >
<arg value="./bundle-messages.sh" />
</exec>
<javac source="${javac.version}" target="${javac.version}"
includeAntRuntime="false"
srcdir="build/messages-src" destdir="build/obj">
<compilerarg line="${javac.compilerargs}" />
</javac>
</target>
<target name="poupdate">
<!-- Update the messages_*.po files. -->
<!-- set if unset -->
<property name="lg2" value="" />
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="true" >
<env key="LG2" value="${lg2}" />
<arg value="./bundle-messages.sh" />
<arg value="-p" />
</exec>
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="true" >
<env key="LG2" value="${lg2}" />
<arg value="./bundle-messages.sh" />
<arg value="-p" />
</exec>
<exec executable="sh" osfamily="windows" failifexecutionfails="true" failonerror="true" >
<env key="LG2" value="${lg2}" />
<arg value="./bundle-messages.sh" />
<arg value="-p" />
</exec>
</target>
<target name="javadoc">
<mkdir dir="./build" />
<mkdir dir="./build/javadoc" />

141
core/java/bundle-messages.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/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.util.messages
TMPFILE=build/javafiles.txt
export TZ=UTC
RC=0
if ! $(which javac > /dev/null 2>&1); then
export JAVAC=${JAVA_HOME}/../bin/javac
fi
if [ "$1" = "-p" ]
then
POUPDATE=1
fi
# on windows, one must specify the path of commnad find
# since windows has its own 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 environment variables to enable this
# add ../java/ so the refs will work in the po file
# do not scan 3rd-party code
JPATHS="../java/src/net/i2p"
for i in ../locale/messages_*.po
do
# get language
LG=${i#../locale/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/util/messages_$LG.class -a \
build/obj/net/i2p/util/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:
# _t("foo")
# _x("foo")
# intl._t("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=_t --keyword=_x --keyword=intl._ --keyword=intl.title \
-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..."
msgfmt -V | grep -q -E ' 0\.((19)|[2-9])'
if [ $? -ne 0 ]
then
# slow way
# 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 -name messages_${LG}.class -exec rm -f {} \;
RC=1
break
fi
else
# fast way
# convert to java files in build/messages-src
TD=build/messages-src-tmp
TDX=$TD/net/i2p/util
TD2=build/messages-src
TDY=$TD2/net/i2p/util
rm -rf $TD
mkdir -p $TD $TDY
msgfmt --java --statistics --source -r $CLASS -l $LG -d $TD $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
mv $TDX/messages_$LG.java $TDY
rm -rf $TD
fi
fi
done
rm -f $TMPFILE
exit $RC

View File

@@ -1454,7 +1454,7 @@ public class DataHelper {
return t.replace(" ", "&nbsp;");
}
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
private static final String BUNDLE_NAME = "net.i2p.util.messages";
private static String _t(String key) {
return Translate.getString(key, I2PAppContext.getGlobalContext(), BUNDLE_NAME);

View File

@@ -158,17 +158,17 @@ abstract class LogWriter implements Runnable {
String arrows = reverse ? (nohtml ? "vvv" : "&darr;&darr;&darr;")
: (nohtml ? "^^^" : "&uarr;&uarr;&uarr;");
return LogRecordFormatter.getWhen(_manager, lastRecord) + ' ' + arrows + ' ' +
_t(dupCount, "1 similar message omitted", "{0} similar messages omitted") + ' ' + arrows +
ngettext("1 similar message omitted", "{0} similar messages omitted", dupCount) + ' ' + arrows +
LogRecordFormatter.NL;
}
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
private static final String BUNDLE_NAME = "net.i2p.util.messages";
/**
* gettext
* @since 0.9.3
*/
private String _t(int a, String b, String c) {
private String ngettext(String b, String c, int a) {
return Translate.getString(a, b, c, _manager.getContext(), BUNDLE_NAME);
}