I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
bundle-messages.sh 2.71 KiB
Newer Older
  • Learn to ignore specific revisions
  • #
    # Update messages_xx.po and messages_xx.class files,
    # from both java and jsp sources.
    
    # Requires installed programs xgettext, msgfmt, msgmerge, and find.
    
    # zzz - public domain
    #
    CLASS=net.i2p.router.web.messages
    TMPFILE=build/javafiles.txt
    
    export TZ=UTC
    
    zzz's avatar
    zzz committed
    #
    # generate strings/Countries.java from ../../../installer/resources/countries.txt
    #
    CFILE=../../../installer/resources/countries.txt
    JFILE=build/Countries.java
    if [ $CFILE -nt $JFILE -o ! -s $JFILE ]
    then
    	mkdir -p build
            echo '// Automatically generated pseudo-java for xgettext - do not edit' > $JFILE
    	echo '// Translators may wish to translate a few of these, do not bother to translate all of them!!' >> $JFILE
    	sed 's/..,\(..*\)/_("\1");/' $CFILE >> $JFILE
    fi
    
    
    zzz's avatar
    zzz committed
    # list specific files in router/ here, so we don't scan the whole tree
    ROUTERFILES="\
       ../../../router/java/src/net/i2p/router/RouterThrottleImpl.java \
       ../../../router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java"
    JPATHS="src ../jsp/WEB-INF strings $JFILE $ROUTERFILES"
    
    for i in ../locale/messages_*.po
    do
    	# get language
    	LG=${i#../locale/messages_}
    	LG=${LG%.po}
    
    	# make list of java files newer than the .po file
    
    zzz's avatar
    zzz committed
    	find $JPATHS -name *.java -newer $i > $TMPFILE
    
    zzz's avatar
    zzz committed
    	if [ -s build/obj/net/i2p/router/web/messages_$LG.class -a \
    	     build/obj/net/i2p/router/web/messages_$LG.class -nt $i -a \
    	     ! -s $TMPFILE ]
    
    	then
    		continue
    	fi
    
    	echo "Generating ${CLASS}_$LG ResourceBundle..."
    
    	# extract strings from java and jsp files, and update messages.po files
    	# translate calls must be one of the forms:
    	# _("foo")
    
    zzz's avatar
    zzz committed
    	# _x("foo")
    
    	# intl._("foo")
    	# intl.title("foo")
    
    	# handler._("foo")
    	# formhandler._("foo")
    
    zzz's avatar
    zzz committed
    	# net.i2p.router.web.Messages.getString("foo")
    
    	# In a jsp, you must use a helper or handler that has the context set.
    	# To start a new translation, copy the header from an old translation to the new .po file,
    	# then ant distclean updater.
    
    zzz's avatar
    zzz committed
    	find $JPATHS -name *.java > $TMPFILE
    
    walking's avatar
    walking committed
    	xgettext -f $TMPFILE -F -L java --from-code=UTF-8 \
    
                     --keyword=_ --keyword=_x --keyword=intl._ --keyword=intl.title \
    
    zzz's avatar
    zzz committed
                     --keyword=handler._ --keyword=formhandler._ \
    
    zzz's avatar
    zzz committed
                     --keyword=net.i2p.router.web.Messages.getString \
    
    	if [ $? -ne 0 ]
    	then
    		echo 'Warning - xgettext failed, not updating translations'
    
    		rm -f ${i}t
    
    	msgmerge -U --backup=none $i ${i}t
    	if [ $? -ne 0 ]
    	then
    		echo 'Warning - msgmerge failed, not updating translations'
    		rm -f ${i}t
    		break
    	fi
    	rm -f ${i}t
    	# so we don't do this again
    	touch $i
    
    
    	# convert to class files in build/obj
    	msgfmt --java -r $CLASS -l $LG -d build/obj $i
    	if [ $? -ne 0 ]
    	then
    
    zzz's avatar
    zzz committed
    		echo 'Warning - msgfmt failed, not updating translations'
    
    		break
    	fi
    done
    rm -f $TMPFILE
    # todo: return failure
    exit 0