source: apps/routerconsole/java/bundle-messages.sh @ 6019cf81

Last change on this file since 6019cf81 was 6019cf81, checked in by zzz <zzz@…>, 11 years ago
  • Console:
    • Tag tunnel status
  • Property mode set to 100755
File size: 2.7 KB
Line 
1#
2# Update messages_xx.po and messages_xx.class files,
3# from both java and jsp sources.
4# Requires installed programs xgettext, msgfmt, msgmerge, and find.
5# zzz - public domain
6#
7CLASS=net.i2p.router.web.messages
8TMPFILE=build/javafiles.txt
9export TZ=UTC
10
11#
12# generate strings/Countries.java from ../../../installer/resources/countries.txt
13#
14CFILE=../../../installer/resources/countries.txt
15JFILE=build/Countries.java
16if [ $CFILE -nt $JFILE -o ! -s $JFILE ]
17then
18        mkdir -p build
19        echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE
20        echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE
21        sed 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE
22fi
23
24# list specific files in router/ here, so we don't scan the whole tree
25ROUTERFILES="\
26   ../../../router/java/src/net/i2p/router/RouterThrottleImpl.java \
27   ../../../router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java"
28JPATHS="src ../jsp/WEB-INF strings $JFILE $ROUTERFILES"
29for i in ../locale/messages_*.po
30do
31        # get language
32        LG=${i#../locale/messages_}
33        LG=${LG%.po}
34
35        # make list of java files newer than the .po file
36        find $JPATHS -name *.java -newer $i > $TMPFILE
37        if [ -s build/obj/net/i2p/router/web/messages_$LG.class -a \
38             build/obj/net/i2p/router/web/messages_$LG.class -nt $i -a \
39             ! -s $TMPFILE ]
40        then
41                continue
42        fi
43
44        echo "Generating ${CLASS}_$LG ResourceBundle..."
45
46        # extract strings from java and jsp files, and update messages.po files
47        # translate calls must be one of the forms:
48        # _("foo")
49        # _x("foo")
50        # intl._("foo")
51        # intl.title("foo")
52        # handler._("foo")
53        # formhandler._("foo")
54        # net.i2p.router.web.Messages.getString("foo")
55        # In a jsp, you must use a helper or handler that has the context set.
56        # To start a new translation, copy the header from an old translation to the new .po file,
57        # then ant distclean updater.
58        find $JPATHS -name *.java > $TMPFILE
59        xgettext -f $TMPFILE -F -L java --from-code=UTF-8 \
60                 --keyword=_ --keyword=_x --keyword=intl._ --keyword=intl.title \
61                 --keyword=handler._ --keyword=formhandler._ \
62                 --keyword=net.i2p.router.web.Messages.getString \
63                 -o ${i}t
64        if [ $? -ne 0 ]
65        then
66                echo 'Warning - xgettext failed, not updating translations'
67                rm -f ${i}t
68                break
69        fi
70        msgmerge -U --backup=none $i ${i}t
71        if [ $? -ne 0 ]
72        then
73                echo 'Warning - msgmerge failed, not updating translations'
74                rm -f ${i}t
75                break
76        fi
77        rm -f ${i}t
78        # so we don't do this again
79        touch $i
80
81        # convert to class files in build/obj
82        msgfmt --java -r $CLASS -l $LG -d build/obj $i
83        if [ $? -ne 0 ]
84        then
85                echo 'Warning - msgfmt failed, not updating translations'
86                break
87        fi
88done
89rm -f $TMPFILE
90# todo: return failure
91exit 0
Note: See TracBrowser for help on using the repository browser.