source: apps/routerconsole/java/bundle-messages.sh @ 7bd83f8

Last change on this file since 7bd83f8 was c0b9fe0, checked in by zzz <zzz@…>, 9 years ago
  • Router: Refactor periodic tasks to their own files
  • Property mode set to 100755
File size: 4.9 KB
Line 
1#
2# Update messages_xx.po and messages_xx.class files,
3# from both java and jsp sources.
4# Requires installed programs xgettext, msgfmt, msgmerge, and find.
5#
6# usage:
7#    bundle-messages.sh (generates the resource bundle from the .po file)
8#    bundle-messages.sh -p (updates the .po file from the source tags, then generates the resource bundle)
9#
10# zzz - public domain
11#
12CLASS=net.i2p.router.web.messages
13TMPFILE=build/javafiles.txt
14export TZ=UTC
15RC=0
16
17if [ "$1" = "-p" ]
18then
19        POUPDATE=1
20fi
21
22# on windows, one must specify the path of commnad find
23# since windows has its own retarded version of find.
24if which find|grep -q -i windows ; then
25        export PATH=.:/bin:/usr/local/bin:$PATH
26fi
27# Fast mode - update ondemond
28# set LG2 to the language you need in envrionment varibales to enable this
29
30#
31# generate strings/Countries.java from ../../../installer/resources/countries.txt
32#
33CFILE=../../../installer/resources/countries.txt
34# add ../java/ so the refs will work in the po file
35JFILE=../java/build/Countries.java
36if [ $CFILE -nt $JFILE -o ! -s $JFILE ]
37then
38        mkdir -p build
39        echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE
40        echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE
41        sed 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE
42fi
43
44# list specific files in core/ and router/ here, so we don't scan the whole tree
45ROUTERFILES="\
46   ../../../core/java/src/net/i2p/data/DataHelper.java \
47   ../../../router/java/src/net/i2p/router/tasks/CoalesceStatsEvent.java \
48   ../../../router/java/src/net/i2p/router/RouterThrottleImpl.java \
49   ../../../router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java \
50   ../../../router/java/src/net/i2p/router/transport/TransportManager.java \
51   ../../../router/java/src/net/i2p/router/transport/GetBidsJob.java \
52   ../../../router/java/src/net/i2p/router/Blocklist.java \
53   ../../../router/java/src/net/i2p/router/transport/ntcp/EstablishState.java \
54   ../../../router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java \
55   ../../../router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java \
56   ../../../router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java \
57   ../../../router/java/src/net/i2p/router/transport/udp/UDPTransport.java \
58   ../../../router/java/src/net/i2p/router/transport/UPnP.java \
59   ../../../router/java/src/net/i2p/router/transport/UPnPManager.java"
60
61# add ../java/ so the refs will work in the po file
62JPATHS="../java/src ../jsp/WEB-INF ../java/strings $JFILE $ROUTERFILES"
63for i in ../locale/messages_*.po
64do
65        # get language
66        LG=${i#../locale/messages_}
67        LG=${LG%.po}
68       
69        # skip, if specified
70        if [ $LG2 ]; then
71                [ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
72        fi
73
74        if [ "$POUPDATE" = "1" ]
75        then
76                # make list of java files newer than the .po file
77                find $JPATHS -name *.java -newer $i > $TMPFILE
78        fi
79
80        if [ -s build/obj/net/i2p/router/web/messages_$LG.class -a \
81             build/obj/net/i2p/router/web/messages_$LG.class -nt $i -a \
82             ! -s $TMPFILE ]
83        then
84                continue
85        fi
86
87        if [ "$POUPDATE" = "1" ]
88        then
89                echo "Updating the $i file from the tags..."
90                # extract strings from java and jsp files, and update messages.po files
91                # translate calls must be one of the forms:
92                # _("foo")
93                # _x("foo")
94                # intl._("foo")
95                # intl.title("foo")
96                # handler._("foo")
97                # formhandler._("foo")
98                # net.i2p.router.web.Messages.getString("foo")
99                # In a jsp, you must use a helper or handler that has the context set.
100                # To start a new translation, copy the header from an old translation to the new .po file,
101                # then ant distclean updater.
102                find $JPATHS -name *.java > $TMPFILE
103                xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
104                         --keyword=_ --keyword=_x --keyword=intl._ --keyword=intl.title \
105                         --keyword=handler._ --keyword=formhandler._ \
106                         --keyword=net.i2p.router.web.Messages.getString \
107                         -o ${i}t
108                if [ $? -ne 0 ]
109                then
110                        echo "ERROR - xgettext failed on ${i}, not updating translations"
111                        rm -f ${i}t
112                        RC=1
113                        break
114                fi
115                msgmerge -U --backup=none $i ${i}t
116                if [ $? -ne 0 ]
117                then
118                        echo "ERROR - msgmerge failed on ${i}, not updating translations"
119                        rm -f ${i}t
120                        RC=1
121                        break
122                fi
123                rm -f ${i}t
124                # so we don't do this again
125                touch $i
126        fi
127
128    if [ "$LG" != "en" ]
129    then
130        # only generate for non-source language
131        echo "Generating ${CLASS}_$LG ResourceBundle..."
132
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/obj -name messages_${LG}.class -exec rm -f {} \;
140            RC=1
141            break
142        fi
143    fi
144done
145rm -f $TMPFILE
146exit $RC
Note: See TracBrowser for help on using the repository browser.