source: apps/desktopgui/bundle-messages.sh @ 46af643

Last change on this file since 46af643 was a13552dd, checked in by dg2-new <dg2-new@…>, 5 years ago

Fix news (ant poupdate), typos in bundle-*

  • Property mode set to 100644
File size: 3.3 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        # convert to class files in build
109        msgfmt --java --statistics -r $CLASS -l $LG -d build $i
110        if [ $? -ne 0 ]
111        then
112            echo "ERROR - msgfmt failed on ${i}, not updating translations"
113            # msgfmt leaves the class file there so the build would work the next time
114            find build -name messages_${LG}.class -exec rm -f {} \;
115            RC=1
116            break
117        fi
118    fi
119done
120rm -f $TMPFILE
121exit $RC
Note: See TracBrowser for help on using the repository browser.