source: apps/routerconsole/java/bundle-messages-news.sh @ 85db853

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

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

  • Property mode set to 100755
File size: 4.0 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.news.messages
14TMPFILE=build/javafiles-news.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# add ../java/ so the refs will work in the po file
36JPATHS="../java/build/News.java"
37for i in ../locale-news/messages_*.po
38do
39        # get language
40        LG=${i#../locale-news/messages_}
41        LG=${LG%.po}
42
43        # skip, if specified
44        if [ $LG2 ]; then
45                [ $LG != $LG2 ] && continue || echo INFO: Language update is set to [$LG2] only.
46        fi
47
48        if [ "$POUPDATE" = "1" ]
49        then
50                # make list of java files newer than the .po file
51                find $JPATHS -name *.java -newer $i > $TMPFILE
52        fi
53        if [ -s build/obj/net/i2p/router/news/messages_$LG.class -a \
54             build/obj/net/i2p/router/news/messages_$LG.class -nt $i -a \
55             ! -s $TMPFILE ]
56        then
57                continue
58        fi
59
60        if [ "$POUPDATE" = "1" ]
61        then
62                echo "Updating the $i file from the tags..."
63                # extract strings from java and jsp files, and update messages.po files
64                # translate calls must be one of the forms:
65                # _t("foo")
66                # _x("foo")
67                # intl._t("foo")
68                # intl.title("foo")
69                # In a jsp, you must use a helper or handler that has the context set.
70                # To start a new translation, copy the header from an old translation to the new .po file,
71                # then ant distclean updater.
72                find $JPATHS -name *.java > $TMPFILE
73                xgettext -f $TMPFILE -L java --from-code=UTF-8 --no-location\
74                         --keyword=_t \
75                         -o ${i}t
76                if [ $? -ne 0 ]
77                then
78                        echo "ERROR - xgettext failed on ${i}, not updating translations"
79                        rm -f ${i}t
80                        RC=1
81                        break
82                fi
83                msgmerge -U --backup=none $i ${i}t
84                if [ $? -ne 0 ]
85                then
86                        echo "ERROR - msgmerge failed on ${i}, not updating translations"
87                        rm -f ${i}t
88                        RC=1
89                        break
90                fi
91                rm -f ${i}t
92                # so we don't do this again
93                touch $i
94        fi
95
96    if [ "$LG" != "en" ]
97    then
98        # only generate for non-source language
99        echo "Generating ${CLASS}_$LG ResourceBundle..."
100
101        msgfmt -V | grep -q '0\.19'
102        if [ $? -ne 0 ]
103        then
104            # slow way
105            # convert to class files in build/obj
106            msgfmt --java --statistics -r $CLASS -l $LG -d build/obj $i
107            if [ $? -ne 0 ]
108            then
109                echo "ERROR - msgfmt failed on ${i}, not updating translations"
110                # msgfmt leaves the class file there so the build would work the next time
111                find build -name messages_${LG}.class -exec rm -f {} \;
112                RC=1
113                break
114            fi
115        else
116            # fast way
117            # convert to java files in build/messages-news-src
118            TD=build/messages-news-src-tmp
119            TDX=$TD/net/i2p/router/news
120            TD2=build/messages-news-src
121            TDY=$TD2/net/i2p/router/news
122            rm -rf $TD
123            mkdir -p $TD $TDY
124            msgfmt --java --statistics --source -r $CLASS -l $LG -d $TD $i
125            if [ $? -ne 0 ]
126            then
127                echo "ERROR - msgfmt failed on ${i}, not updating translations"
128                # msgfmt leaves the class file there so the build would work the next time
129                find build/obj -name messages_${LG}.class -exec rm -f {} \;
130                RC=1
131                break
132            fi
133            mv $TDX/messages_$LG.java $TDY
134            rm -rf $TD
135        fi
136    fi
137done
138rm -f $TMPFILE
139exit $RC
Note: See TracBrowser for help on using the repository browser.