source: apps/susimail/bundle-messages.sh @ 2de36ee

Last change on this file since 2de36ee 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 100644
File size: 3.9 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=i2p.susi.webmail.messages
14TMPFILE=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# add ../java/ so the refs will work in the po file
36JPATHS="src"
37for i in locale/messages_*.po
38do
39        # get language
40        LG=${i#locale/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
54        if [ -s src/WEB-INF/classes/i2p/susi/webmail/messages_$LG.class -a \
55             src/WEB-INF/classes/i2p/susi/webmail/messages_$LG.class -nt $i -a \
56             ! -s $TMPFILE ]
57        then
58                continue
59        fi
60
61        if [ "$POUPDATE" = "1" ]
62        then
63        echo "Updating the $i file from the tags..."
64                # extract strings from java and jsp files, and update messages.po files
65                # translate calls must be one of the forms:
66                # _t("foo")
67                # _x("foo")
68                # To start a new translation, copy the header from an old translation to the new .po file,
69                # then ant distclean poupdate.
70                find $JPATHS -name *.java > $TMPFILE
71                xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
72                         --keyword=_t --keyword=_x \
73                         -o ${i}t
74                if [ $? -ne 0 ]
75                then
76                        echo "ERROR - xgettext failed on ${i}, not updating translations"
77                        rm -f ${i}t
78                        RC=1
79                        break
80                fi
81                msgmerge -U --backup=none $i ${i}t
82                if [ $? -ne 0 ]
83                then
84                        echo "ERROR - msgmerge failed on ${i}, not updating translations"
85                        rm -f ${i}t
86                        RC=1
87                        break
88                fi
89                rm -f ${i}t
90                # so we don't do this again
91                touch $i
92        fi
93
94    if [ "$LG" != "en" ]
95    then
96        # only generate for non-source language
97        echo "Generating ${CLASS}_$LG ResourceBundle..."
98
99        msgfmt -V | grep -q '0\.19'
100        if [ $? -ne 0 ]
101        then
102            # slow way
103            # convert to class files in src/WEB-INF/classes
104            msgfmt --java --statistics -r $CLASS -l $LG -d src/WEB-INF/classes $i
105            if [ $? -ne 0 ]
106            then
107                echo "ERROR - msgfmt failed on ${i}, not updating translations"
108                # msgfmt leaves the class file there so the build would work the next time
109                find src/WEB-INF/classes -name messages_${LG}.class -exec rm -f {} \;
110                RC=1
111                break
112            fi
113        else
114            # fast way
115            # convert to java files in build/messages-src
116            TD=build/messages-src-tmp
117            TDX=$TD/i2p/susi/webmail
118            TD2=build/messages-src
119            TDY=$TD2/i2p/susi/webmail
120            rm -rf $TD
121            mkdir -p $TD $TDY
122            msgfmt --java --statistics --source -r $CLASS -l $LG -d $TD $i
123            if [ $? -ne 0 ]
124            then
125                echo "ERROR - msgfmt failed on ${i}, not updating translations"
126                # msgfmt leaves the class file there so the build would work the next time
127                find src/WEB-INF/classes -name messages_${LG}.class -exec rm -f {} \;
128                RC=1
129                break
130            fi
131            mv $TDX/messages_$LG.java $TDY
132            rm -rf $TD
133        fi
134    fi
135done
136rm -f $TMPFILE
137# todo: return failure
138exit $RC
Note: See TracBrowser for help on using the repository browser.