* Translations: Move country names to a new resource bundle

This commit is contained in:
zzz
2013-10-14 15:29:12 +00:00
parent 0c0a25b038
commit 3ec602865d
54 changed files with 15811 additions and 22706 deletions

View File

@ -97,7 +97,7 @@
</exec>
</target>
<target name="jar1" depends="compile, bundle-news, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
<target name="jar1" depends="compile, bundle-news, bundle-countries, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
<!-- set if unset -->
<property name="workspace.changes.j.tr" value="" />
<jar destfile="./build/routerconsole.jar" basedir="./build/obj" includes="**/*.class">
@ -179,6 +179,19 @@
</exec>
</target>
<target name="bundle-countries" unless="no.bundle">
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="${require.gettext}" >
<env key="JAVA_HOME" value="${java.home}" />
<arg value="./bundle-messages-countries.sh" />
</exec>
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="${require.gettext}" >
<arg value="./bundle-messages-countries.sh" />
</exec>
<exec executable="sh" osfamily="windows" failifexecutionfails="false" >
<arg value="./bundle-messages-countries.sh" />
</exec>
</target>
<target name="extractProxyTags">
<java classname="net.i2p.util.TranslateReader" fork="true" failonerror="true">
<classpath>
@ -205,6 +218,21 @@
</exec>
</target>
<target name="poupdate-countries" depends="extractProxyTags">
<exec executable="sh" osfamily="unix" failifexecutionfails="true" failonerror="true" >
<arg value="./bundle-messages-countries.sh" />
<arg value="-p" />
</exec>
<exec executable="sh" osfamily="mac" failifexecutionfails="true" failonerror="true" >
<arg value="./bundle-messages-countries.sh" />
<arg value="-p" />
</exec>
<exec executable="sh" osfamily="windows" failifexecutionfails="true" failonerror="true" >
<arg value="./bundle-messages-countries.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" />

View File

@ -0,0 +1,128 @@
#!/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.router.countries.messages
TMPFILE=build/javafiles-countries.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 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
#
# generate strings/Countries.java from ../../../installer/resources/countries.txt
#
CFILE=../../../installer/resources/countries.txt
# add ../java/ so the refs will work in the po file
JFILE=../java/build/Countries.java
if [ $CFILE -nt $JFILE -o ! -s $JFILE ]
then
mkdir -p build
echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE
echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE
sed -e '/^#/d' -e 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE
fi
# add ../java/ so the refs will work in the po file
JPATHS="$JFILE"
for i in ../locale-countries/messages_*.po
do
# get language
LG=${i#../locale-countries/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/router/countries/messages_$LG.class -a \
build/obj/net/i2p/router/countries/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 -L java --from-code=UTF-8 --no-location\
--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

View File

@ -32,19 +32,6 @@ fi
# Fast mode - update ondemond
# set LG2 to the language you need in envrionment varibales to enable this
#
# generate strings/Countries.java from ../../../installer/resources/countries.txt
#
CFILE=../../../installer/resources/countries.txt
# add ../java/ so the refs will work in the po file
JFILE=../java/build/Countries.java
if [ $CFILE -nt $JFILE -o ! -s $JFILE ]
then
mkdir -p build
echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE
echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE
sed -e '/^#/d' -e 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE
fi
# list specific files in core/ and router/ here, so we don't scan the whole tree
ROUTERFILES="\
@ -65,7 +52,7 @@ ROUTERFILES="\
../../../router/java/src/net/i2p/router/transport/UPnPManager.java"
# add ../java/ so the refs will work in the po file
JPATHS="../java/src ../jsp/WEB-INF ../java/strings $JFILE $ROUTERFILES"
JPATHS="../java/src ../jsp/WEB-INF ../java/strings $ROUTERFILES"
for i in ../locale/messages_*.po
do
# get language

View File

@ -35,6 +35,7 @@ import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.util.HashDistance; // debug
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.ObjectCounter;
import net.i2p.util.Translate;
import net.i2p.util.VersionComparator;
public class NetDbRenderer {
@ -332,7 +333,7 @@ public class NetDbRenderer {
int num = countries.count(country);
buf.append("<tr><td><img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append("\"");
buf.append(" src=\"/flags.jsp?c=").append(country).append("\"> ");
buf.append(_(_context.commSystem().getCountryName(country)));
buf.append(getTranslatedCountry(country));
buf.append("</td><td align=\"center\">").append(num).append("</td></tr>\n");
}
buf.append("</table>\n");
@ -349,6 +350,18 @@ public class NetDbRenderer {
out.flush();
}
private static final String COUNTRY_BUNDLE_NAME = "net.i2p.router.countries.messages";
/**
* Countries now in a separate bundle
* @param code two-letter country code
* @since 0.9.9
*/
private String getTranslatedCountry(String code) {
String name = _context.commSystem().getCountryName(code);
return Translate.getString(name, _context, COUNTRY_BUNDLE_NAME);
}
/** sort by translated country name using rules for the current language setting */
private class CountryComparator implements Comparator<String> {
Collator coll;
@ -359,8 +372,8 @@ public class NetDbRenderer {
}
public int compare(String l, String r) {
return coll.compare(_(_context.commSystem().getCountryName(l)),
_(_context.commSystem().getCountryName(r)));
return coll.compare(getTranslatedCountry(l),
getTranslatedCountry(r));
}
}
@ -396,7 +409,7 @@ public class NetDbRenderer {
String country = _context.commSystem().getCountry(info.getIdentity().getHash());
if(country != null) {
buf.append("<img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append('\"');
buf.append(" title=\"").append(_(_context.commSystem().getCountryName(country))).append('\"');
buf.append(" title=\"").append(getTranslatedCountry(country)).append('\"');
buf.append(" src=\"/flags.jsp?c=").append(country).append("\"> ");
}
for (RouterAddress addr : info.getAddresses()) {