2012-12-23 17:35:07 +00:00
|
|
|
#!/bin/sh
|
2009-12-09 20:54:10 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2021-01-03 09:55:42 -05:00
|
|
|
cd `dirname $0`
|
2009-12-10 02:12:18 +00:00
|
|
|
CLASS=org.klomp.snark.web.messages
|
2009-12-09 20:54:10 +00:00
|
|
|
TMPFILE=build/javafiles.txt
|
|
|
|
export TZ=UTC
|
2011-06-13 14:31:41 +00:00
|
|
|
RC=0
|
2009-12-09 20:54:10 +00:00
|
|
|
|
2013-09-20 02:00:41 +00:00
|
|
|
if ! $(which javac > /dev/null 2>&1); then
|
2013-09-20 01:21:43 +00:00
|
|
|
export JAVAC=${JAVA_HOME}/../bin/javac
|
|
|
|
fi
|
|
|
|
|
2009-12-09 20:54:10 +00:00
|
|
|
if [ "$1" = "-p" ]
|
|
|
|
then
|
|
|
|
POUPDATE=1
|
|
|
|
fi
|
|
|
|
|
2011-02-12 11:30:21 +00:00
|
|
|
# on windows, one must specify the path of commnad find
|
2015-05-12 18:46:40 +00:00
|
|
|
# since windows has its own version of find.
|
2011-02-12 11:30:21 +00:00
|
|
|
if which find|grep -q -i windows ; then
|
|
|
|
export PATH=.:/bin:/usr/local/bin:$PATH
|
|
|
|
fi
|
|
|
|
# Fast mode - update ondemond
|
2015-09-25 21:49:47 +00:00
|
|
|
# set LG2 to the language you need in environment variables to enable this
|
2011-02-12 11:30:21 +00:00
|
|
|
|
2009-12-09 20:54:10 +00:00
|
|
|
# add ../java/ so the refs will work in the po file
|
|
|
|
JPATHS="../java/src"
|
|
|
|
for i in ../locale/messages_*.po
|
|
|
|
do
|
|
|
|
# get language
|
|
|
|
LG=${i#../locale/messages_}
|
|
|
|
LG=${LG%.po}
|
|
|
|
|
2011-02-12 11:30:21 +00:00
|
|
|
# skip, if specified
|
|
|
|
if [ $LG2 ]; then
|
|
|
|
[ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
|
|
|
|
fi
|
|
|
|
|
2009-12-09 20:54:10 +00:00
|
|
|
if [ "$POUPDATE" = "1" ]
|
|
|
|
then
|
|
|
|
# make list of java files newer than the .po file
|
|
|
|
find $JPATHS -name *.java -newer $i > $TMPFILE
|
|
|
|
fi
|
|
|
|
|
2009-12-10 02:12:18 +00:00
|
|
|
if [ -s build/obj/org/klomp/snark/web/messages_$LG.class -a \
|
|
|
|
build/obj/org/klomp/snark/web/messages_$LG.class -nt $i -a \
|
2009-12-09 20:54:10 +00:00
|
|
|
! -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:
|
2015-09-25 19:55:36 +00:00
|
|
|
# _t("foo")
|
2009-12-09 20:54:10 +00:00
|
|
|
# _x("foo")
|
|
|
|
# To start a new translation, copy the header from an old translation to the new .po file,
|
|
|
|
# then ant distclean poupdate.
|
|
|
|
find $JPATHS -name *.java > $TMPFILE
|
2010-06-02 18:12:46 +00:00
|
|
|
xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
|
2015-09-25 19:55:36 +00:00
|
|
|
--keyword=_t --keyword=_x \
|
2009-12-09 20:54:10 +00:00
|
|
|
-o ${i}t
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2011-06-13 14:31:41 +00:00
|
|
|
echo "ERROR - xgettext failed on ${i}, not updating translations"
|
2009-12-09 20:54:10 +00:00
|
|
|
rm -f ${i}t
|
2011-06-13 14:31:41 +00:00
|
|
|
RC=1
|
2009-12-09 20:54:10 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
msgmerge -U --backup=none $i ${i}t
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2011-06-13 14:31:41 +00:00
|
|
|
echo "ERROR - msgmerge failed on ${i}, not updating translations"
|
2009-12-09 20:54:10 +00:00
|
|
|
rm -f ${i}t
|
2011-06-13 14:31:41 +00:00
|
|
|
RC=1
|
2009-12-09 20:54:10 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
rm -f ${i}t
|
|
|
|
# so we don't do this again
|
|
|
|
touch $i
|
|
|
|
fi
|
|
|
|
|
2011-02-13 17:11:53 +00:00
|
|
|
if [ "$LG" != "en" ]
|
|
|
|
then
|
|
|
|
# only generate for non-source language
|
|
|
|
echo "Generating ${CLASS}_$LG ResourceBundle..."
|
2009-12-09 20:54:10 +00:00
|
|
|
|
2019-10-23 11:00:23 +00:00
|
|
|
msgfmt -V | grep -q -E ' 0\.((19)|[2-9])'
|
2011-02-13 17:11:53 +00:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2016-05-07 12:57:49 +00:00
|
|
|
# slow way
|
|
|
|
# convert to class files in build/obj
|
2020-05-05 10:36:56 +00:00
|
|
|
msgfmt --java2 --statistics -r $CLASS -l $LG -d build/obj $i
|
2016-05-07 12:57:49 +00:00
|
|
|
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/org/klomp/snark/web
|
|
|
|
TD2=build/messages-src
|
|
|
|
TDY=$TD2/org/klomp/snark/web
|
|
|
|
rm -rf $TD
|
|
|
|
mkdir -p $TD $TDY
|
2020-05-05 10:36:56 +00:00
|
|
|
msgfmt --java2 --statistics --source -r $CLASS -l $LG -d $TD $i
|
2016-05-07 12:57:49 +00:00
|
|
|
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
|
2011-02-13 17:11:53 +00:00
|
|
|
fi
|
|
|
|
fi
|
2009-12-09 20:54:10 +00:00
|
|
|
done
|
|
|
|
rm -f $TMPFILE
|
2011-06-13 14:31:41 +00:00
|
|
|
exit $RC
|