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 | # |
---|
7 | |
---|
8 | ## launching sh.exe with -login parameter will open a shell with the current path always pointing to \bin\ |
---|
9 | ## need to cd into our orignal path - where we call sh.exe from. |
---|
10 | |
---|
11 | cd $CALLFROM |
---|
12 | echo $PWD |
---|
13 | |
---|
14 | ## except this everything is the same with bundle-message.sh |
---|
15 | ## walking - public domain :-D |
---|
16 | |
---|
17 | |
---|
18 | CLASS=net.i2p.router.web.messages |
---|
19 | TMPFILE=build/javafiles.txt |
---|
20 | export TZ=UTC |
---|
21 | |
---|
22 | # |
---|
23 | # generate strings/Countries.java from ../../../installer/resources/countries.txt |
---|
24 | # |
---|
25 | CFILE=../../../installer/resources/countries.txt |
---|
26 | JFILE=build/Countries.java |
---|
27 | if [ $CFILE -nt $JFILE -o ! -s $JFILE ] |
---|
28 | then |
---|
29 | mkdir -p build |
---|
30 | echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE |
---|
31 | echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE |
---|
32 | sed 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE |
---|
33 | fi |
---|
34 | |
---|
35 | # list specific files in router/ here, so we don't scan the whole tree |
---|
36 | ROUTERFILES="\ |
---|
37 | ../../../router/java/src/net/i2p/router/RouterThrottleImpl.java \ |
---|
38 | ../../../router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java" |
---|
39 | JPATHS="src ../jsp/WEB-INF strings $JFILE $ROUTERFILES" |
---|
40 | for i in ../locale/messages_*.po |
---|
41 | do |
---|
42 | # get language |
---|
43 | LG=${i#../locale/messages_} |
---|
44 | LG=${LG%.po} |
---|
45 | |
---|
46 | # make list of java files newer than the .po file |
---|
47 | find $JPATHS -name *.java -newer $i > $TMPFILE |
---|
48 | if [ -s build/obj/net/i2p/router/web/messages_$LG.class -a \ |
---|
49 | build/obj/net/i2p/router/web/messages_$LG.class -nt $i -a \ |
---|
50 | ! -s $TMPFILE ] |
---|
51 | then |
---|
52 | continue |
---|
53 | fi |
---|
54 | |
---|
55 | echo "Generating ${CLASS}_$LG ResourceBundle..." |
---|
56 | |
---|
57 | # extract strings from java and jsp files, and update messages.po files |
---|
58 | # translate calls must be one of the forms: |
---|
59 | # _("foo") |
---|
60 | # _x("foo") |
---|
61 | # intl._("foo") |
---|
62 | # intl.title("foo") |
---|
63 | # handler._("foo") |
---|
64 | # formhandler._("foo") |
---|
65 | # net.i2p.router.web.Messages.getString("foo") |
---|
66 | # In a jsp, you must use a helper or handler that has the context set. |
---|
67 | # To start a new translation, copy the header from an old translation to the new .po file, |
---|
68 | # then ant distclean updater. |
---|
69 | find $JPATHS -name *.java > $TMPFILE |
---|
70 | xgettext -f $TMPFILE -F -L java --from-code=UTF-8 \ |
---|
71 | --keyword=_ --keyword=_x --keyword=intl._ --keyword=intl.title \ |
---|
72 | --keyword=handler._ --keyword=formhandler._ \ |
---|
73 | --keyword=net.i2p.router.web.Messages.getString \ |
---|
74 | -o ${i}t |
---|
75 | if [ $? -ne 0 ] |
---|
76 | then |
---|
77 | echo 'Warning - xgettext failed, not updating translations' |
---|
78 | rm -f ${i}t |
---|
79 | break |
---|
80 | fi |
---|
81 | msgmerge -U --backup=none $i ${i}t |
---|
82 | if [ $? -ne 0 ] |
---|
83 | then |
---|
84 | echo 'Warning - msgmerge failed, not updating translations' |
---|
85 | rm -f ${i}t |
---|
86 | break |
---|
87 | fi |
---|
88 | rm -f ${i}t |
---|
89 | # so we don't do this again |
---|
90 | touch $i |
---|
91 | |
---|
92 | # convert to class files in build/obj |
---|
93 | msgfmt --java -r $CLASS -l $LG -d build/obj $i |
---|
94 | if [ $? -ne 0 ] |
---|
95 | then |
---|
96 | echo 'Warning - msgfmt failed, not updating translations' |
---|
97 | break |
---|
98 | fi |
---|
99 | done |
---|
100 | rm -f $TMPFILE |
---|
101 | # todo: return failure |
---|
102 | exit 0 |
---|