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