#! /bin/bash #create a list of all languages with existing translation of Name if [ ! -f langs.txt ]; then for i in menu-data/*desktop; do awk -F [][] '/^Name/ {print $2}' $i >> langs.txt; done sort -u langs.txt > po/LINGUAS echo "creating po/LINGUAS done" fi DIRS="\ menu-data-additional menu-data" cat po/LINGUAS | while read LANG; do OUTFILE=po/$LANG.po #remove existing po files if [ -f $OUTFILE ] ; then rm $OUTFILE; #echo "removed $OUTFILE"; fi OUTFILE=po/$LANG-tmp.po #add some content header info to make gettext happy echo "msgid \"\"" > $OUTFILE echo "msgstr \"\"" >> $OUTFILE echo "\"Project-Id-Version: app-install-data\n\"" >> $OUTFILE echo "\"PO-Revision-Date: \n\"" >> $OUTFILE echo "\"Last-Translator: \n\"" >> $OUTFILE echo "\"Language-Team: \n\"" >> $OUTFILE echo "\"MIME-Version: 1.0\n\"" >> $OUTFILE echo "\"Content-Type: text/plain; charset=UTF-8\n\"" >> $OUTFILE echo "\"Content-Transfer-Encoding: 8bit\n\"" >> $OUTFILE echo "" >> $OUTFILE done for d in $DIRS; do for FILE in $d/*desktop; do # some devs are still not using utf-8... ENC=`file -i $FILE | cut -d " " -f3`; if [ "$ENC" = "charset=iso-8859-1" ] ; then iconv -c -f iso-8859-1 -t utf-8 $FILE > $FILE-u8; mv $FILE-u8 $FILE; echo "converted $FILE"; fi for FIELD in Name Comment GenericName ; do #extract original string MSGID=`grep "^$FIELD=" $FILE | cut -d = -f2` if [ -n "$MSGID" ]; then #escape ", if any MSGID=`echo $MSGID | sed -e 's/\"/\\\"/g'` # filter out the languages the field is translated into # fixme: this could be faster... awk -v field=^$FIELD '{FS="[][]"} $0 ~ field {if ($2 != "") print $2}' $FILE | while read LANG; do #is it translated? MSGSTR=`awk -v field=^$FIELD -v lang=$LANG '{FS="[],[,=]"} $0 ~ field {if ($2 == lang) {print $4}}' $FILE` if [ -n "$MSGSTR" ] ; then # escape " and \, if any. the latter is necessary because of RTL langugaes - ar and he # fixme: why does not work the last sed expression? MSGSTR=`echo $MSGSTR | sed -e 's/\"/\\\"/g'` #-e 's/\\/\\\\/'` # write out what we have, no translation = no output OUTFILE=po/$LANG-tmp.po echo "#. $FILE:$FIELD" >> $OUTFILE; echo msgid \"$MSGID\" >> $OUTFILE; echo msgstr \"$MSGSTR\" >> $OUTFILE; echo "" >> $OUTFILE; fi done fi done echo "processing $FILE done" done done # there will be duplicate messages, get rid of those cat po/LINGUAS | while read LANG; do msguniq --use-first po/$LANG-tmp.po > po/$LANG.po; echo "msguniq done for $LANG" # not needed anymore rm po/$LANG-tmp.po; done