source: apps/desktopgui/bundle-messages.sh @ 3054a24

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