source: apps/i2ptunnel/java/bundle-messages.sh @ d4ea7dc

Last change on this file since d4ea7dc was 5d93ca1, checked in by zzz <zzz@…>, 4 years ago

Build: Add back the old, slow way to build bundles
for gettext < 0.19

  • Property mode set to 100755
File size: 4.1 KB
Line 
1#!/bin/sh
2
3# Update messages_xx.po and messages_xx.class files,
4# from both java and jsp sources.
5# Requires installed programs xgettext, msgfmt, msgmerge, and find.
6#
7# usage:
8#    bundle-messages.sh (generates the resource bundle from the .po file)
9#    bundle-messages.sh -p (updates the .po file from the source tags, then generates the resource bundle)
10#
11# zzz - public domain
12#
13CLASS=net.i2p.i2ptunnel.web.messages
14TMPFILE=build/javafiles.txt
15export TZ=UTC
16RC=0
17if ! $(which javac > /dev/null 2>&1); then
18    export JAVAC="${JAVA_HOME}/../bin/javac"
19fi
20
21if [ "$1" = "-p" ]
22then
23        POUPDATE=1
24fi
25
26# on windows, one must specify the path of commnad find
27# since windows has its own version of find.
28if which find|grep -q -i windows ; then
29        export PATH=.:/bin:/usr/local/bin:$PATH
30fi
31# Fast mode - update ondemond
32# set LG2 to the language you need in environment variables to enable this
33
34# add ../java/ so the refs will work in the po file
35JPATHS="../java/src/net/i2p/i2ptunnel/web ../jsp/WEB-INF"
36for i in ../locale/messages_*.po
37do
38        # get language
39        LG=${i#../locale/messages_}
40        LG=${LG%.po}
41
42        # skip, if specified
43        if [ $LG2 ]; then
44                [ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
45        fi
46
47        if [ "$POUPDATE" = "1" ]
48        then
49                # make list of java files newer than the .po file
50                find $JPATHS -name *.java -newer $i > $TMPFILE
51        fi
52        if [ -s ../jsp/WEB-INF/classes/net/i2p/i2ptunnel/web/messages_$LG.class -a \
53             ../jsp/WEB-INF/classes/net/i2p/i2ptunnel/web/messages_$LG.class -nt $i -a \
54             ! -s $TMPFILE ]
55        then
56                continue
57        fi
58
59        if [ "$POUPDATE" = "1" ]
60        then
61                echo "Updating the $i file from the tags..."
62                # extract strings from java and jsp files, and update messages.po files
63                # translate calls must be one of the forms:
64                # _t("foo")
65                # _x("foo")
66                # intl._t("foo")
67                # intl.title("foo")
68                # In a jsp, you must use a helper or handler that has the context set.
69                # To start a new translation, copy the header from an old translation to the new .po file,
70                # then ant distclean updater.
71                find $JPATHS -name *.java > $TMPFILE
72                xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
73                         --keyword=_t --keyword=_x --keyword=intl._ --keyword=intl.title \
74                         -o ${i}t
75                if [ $? -ne 0 ]
76                then
77                        echo "ERROR - xgettext failed on ${i}, not updating translations"
78                        rm -f ${i}t
79                        RC=1
80                        break
81                fi
82                msgmerge -U --backup=none $i ${i}t
83                if [ $? -ne 0 ]
84                then
85                        echo "ERROR - msgmerge failed on ${i}, not updating translations"
86                        rm -f ${i}t
87                        RC=1
88                        break
89                fi
90                rm -f ${i}t
91                # so we don't do this again
92                touch $i
93        fi
94
95    if [ "$LG" != "en" ]
96    then
97        # only generate for non-source language
98        echo "Generating ${CLASS}_$LG ResourceBundle..."
99
100        msgfmt -V | grep -q '0\.19'
101        if [ $? -ne 0 ]
102        then
103            # slow way
104            # convert to class files in jsp/WEB-INF/classes
105            msgfmt --java --statistics -r $CLASS -l $LG -d ../jsp/WEB-INF/classes $i
106            if [ $? -ne 0 ]
107            then
108                echo "ERROR - msgfmt failed on ${i}, not updating translations"
109                # msgfmt leaves the class file there so the build would work the next time
110                find build -name messages_${LG}.class -exec rm -f {} \;
111                RC=1
112                break
113            fi
114        else
115            # fast way
116            # convert to java files in build/messages-src
117            TD=build/messages-src-tmp
118            TDX=$TD/net/i2p/i2ptunnel/web
119            TD2=build/messages-src
120            TDY=$TD2/net/i2p/i2ptunnel/web
121            rm -rf $TD
122            mkdir -p $TD $TDY
123            msgfmt --java --statistics --source -r $CLASS -l $LG -d $TD $i
124            if [ $? -ne 0 ]
125            then
126                echo "ERROR - msgfmt failed on ${i}, not updating translations"
127                # msgfmt leaves the class file there so the build would work the next time
128                find src/WEB-INF/classes -name messages_${LG}.class -exec rm -f {} \;
129                RC=1
130                break
131            fi
132            mv $TDX/messages_$LG.java $TDY
133            rm -rf $TD
134        fi
135    fi
136done
137rm -f $TMPFILE
138exit $RC
Note: See TracBrowser for help on using the repository browser.