source: apps/ministreaming/java/bundle-messages.sh @ 7c3d3b4

Last change on this file since 7c3d3b4 was 7c3d3b4, checked in by zzz <zzz@…>, 6 years ago

fix dependency checking for ministreaming po files

  • Property mode set to 100755
File size: 2.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=net.i2p.client.streaming.messages
14TMPFILE=build/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 retarded 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 envrionment varibales to enable this
34
35# add ../java/ so the refs will work in the po file
36JPATHS="../java/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 build/obj/net/i2p/client/streaming/messages_$LG.class -a \
55             build/obj/net/i2p/client/streaming/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                # _("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=_ --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        # convert to class files in build/obj
100        msgfmt --java --statistics -r $CLASS -l $LG -d build/obj $i
101        if [ $? -ne 0 ]
102        then
103            echo "ERROR - msgfmt failed on ${i}, not updating translations"
104            # msgfmt leaves the class file there so the build would work the next time
105            find build/obj -name messages_${LG}.class -exec rm -f {} \;
106            RC=1
107            break
108        fi
109    fi
110done
111rm -f $TMPFILE
112exit $RC
Note: See TracBrowser for help on using the repository browser.