source: apps/routerconsole/java/bundle-messages.sh

Last change on this file was 8cd7e7d, checked in by zzz <zzz@…>, 18 months ago

poupdate-source for 0.9.38
Fix poupdate script to not pick up tags in 3rd party libs

  • Property mode set to 100755
File size: 5.5 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.router.web.messages
14TMPFILE=build/javafiles.txt
15export TZ=UTC
16RC=0
17
18if ! $(which javac > /dev/null 2>&1); then
19    export JAVAC=${JAVA_HOME}/../bin/javac
20fi
21
22if [ "$1" = "-p" ]
23then
24        POUPDATE=1
25fi
26
27# on windows, one must specify the path of commnad find
28# since windows has its own version of find.
29if which find|grep -q -i windows ; then
30        export PATH=.:/bin:/usr/local/bin:$PATH
31fi
32# Fast mode - update ondemond
33# set LG2 to the language you need in environment variables to enable this
34
35
36# list specific files in core/ and router/ here, so we don't scan the whole tree
37ROUTERFILES="\
38   ../../../core/java/src/net/i2p/data/DataHelper.java \
39   ../../../router/java/src/net/i2p/router/Blocklist.java \
40   ../../../router/java/src/net/i2p/router/CommSystemFacade.java \
41   ../../../router/java/src/net/i2p/router/RouterThrottleImpl.java \
42   ../../../router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java \
43   ../../../router/java/src/net/i2p/router/tasks/CoalesceStatsEvent.java \
44   ../../../router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java \
45   ../../../router/java/src/net/i2p/router/transport/GetBidsJob.java \
46   ../../../router/java/src/net/i2p/router/transport/TransportManager.java \
47   ../../../router/java/src/net/i2p/router/transport/UPnP.java \
48   ../../../router/java/src/net/i2p/router/transport/UPnPManager.java \
49   ../../../router/java/src/net/i2p/router/transport/ntcp/EstablishState.java \
50   ../../../router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java \
51   ../../../router/java/src/net/i2p/router/transport/udp/UDPTransport.java \
52   ../../../router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java \
53   ../../../core/java/src/net/i2p/util/LogWriter.java \
54"
55
56# add ../java/ so the refs will work in the po file
57# do not scan 3rd-party code in java/src/com or java/src/edu
58JPATHS="../java/src/net ../jsp/WEB-INF ../java/strings $ROUTERFILES"
59for i in ../locale/messages_*.po
60do
61        # get language
62        LG=${i#../locale/messages_}
63        LG=${LG%.po}
64       
65        # skip, if specified
66        if [ $LG2 ]; then
67                [ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
68        fi
69
70        if [ "$POUPDATE" = "1" ]
71        then
72                # make list of java files newer than the .po file
73                find $JPATHS -name *.java -newer $i > $TMPFILE
74        fi
75
76        if [ -s build/obj/net/i2p/router/web/messages_$LG.class -a \
77             build/obj/net/i2p/router/web/messages_$LG.class -nt $i -a \
78             ! -s $TMPFILE ]
79        then
80                continue
81        fi
82
83        if [ "$POUPDATE" = "1" ]
84        then
85                echo "Updating the $i file from the tags..."
86                # extract strings from java and jsp files, and update messages.po files
87                # translate calls must be one of the forms:
88                # _t("foo")
89                # _x("foo")
90                # intl._t("foo")
91                # intl.title("foo")
92                # handler._t("foo")
93                # formhandler._t("foo")
94                # net.i2p.router.web.Messages.getString("foo")
95                # In a jsp, you must use a helper or handler that has the context set.
96                # To start a new translation, copy the header from an old translation to the new .po file,
97                # then ant distclean updater.
98                find $JPATHS -name *.java > $TMPFILE
99                xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
100                         --keyword=_t --keyword=_x --keyword=intl._ --keyword=intl.title \
101                         --keyword=handler._ --keyword=formhandler._ \
102                         --keyword=net.i2p.router.web.Messages.getString \
103                         -o ${i}t
104                if [ $? -ne 0 ]
105                then
106                        echo "ERROR - xgettext failed on ${i}, not updating translations"
107                        rm -f ${i}t
108                        RC=1
109                        break
110                fi
111                msgmerge -U --backup=none $i ${i}t
112                if [ $? -ne 0 ]
113                then
114                        echo "ERROR - msgmerge failed on ${i}, not updating translations"
115                        rm -f ${i}t
116                        RC=1
117                        break
118                fi
119                rm -f ${i}t
120                # so we don't do this again
121                touch $i
122        fi
123
124    if [ "$LG" != "en" ]
125    then
126        # only generate for non-source language
127        echo "Generating ${CLASS}_$LG ResourceBundle..."
128
129        msgfmt -V | grep -q '0\.19'
130        if [ $? -ne 0 ]
131        then
132            # slow way
133            # convert to class files in build/obj
134            msgfmt --java --statistics -r $CLASS -l $LG -d build/obj $i
135            if [ $? -ne 0 ]
136            then
137                echo "ERROR - msgfmt failed on ${i}, not updating translations"
138                # msgfmt leaves the class file there so the build would work the next time
139                find build -name messages_${LG}.class -exec rm -f {} \;
140                RC=1
141                break
142            fi
143        else
144            # fast way
145            # convert to java files in build/messages-src
146            TD=build/messages-src-tmp
147            TDX=$TD/net/i2p/router/web
148            TD2=build/messages-src
149            TDY=$TD2/net/i2p/router/web
150            rm -rf $TD
151            mkdir -p $TD $TDY
152            msgfmt --java --statistics --source -r $CLASS -l $LG -d $TD $i
153            if [ $? -ne 0 ]
154            then
155                echo "ERROR - msgfmt failed on ${i}, not updating translations"
156                # msgfmt leaves the class file there so the build would work the next time
157                find build/obj -name messages_${LG}.class -exec rm -f {} \;
158                RC=1
159                break
160            fi
161            mv $TDX/messages_$LG.java $TDY
162            rm -rf $TD
163        fi
164    fi
165done
166rm -f $TMPFILE
167exit $RC
Note: See TracBrowser for help on using the repository browser.