#!/bin/bash

rm -f difftranslations

for i in *.po
do
  # Convert the file into UTF-8 (if necessary)
  ISUTF8=`file $i | grep UTF-8`
  if [ "x$ISUTF8" = "x" ]  
  then
    FILEENC=`grep "Content-Type: text/plain; charset=" $i | sed -e 's/.*=\\(.*\\)\\\\n.*/\\1/'`
    recode $FILEENC..UTF-8 $i
  fi

  echo `basename $i .po` >> difftranslations
  grep -C 1 'Only in ' $i | tail -n 1 >> difftranslations
  grep -C 1 'Files %s and %s are identical' $i | tail -n 1 >> difftranslations
  grep -C 1 'Files %s and %s differ' $i | tail -n 1 >> difftranslations
  grep -C 1 'Binary files %s and %s differ' $i | tail -n 1 >> difftranslations
  grep -C 1 'File %s is a %s while file %s is a %s' $i | tail -n 1 >> difftranslations
  grep -C 1 'No newline at end of file' $i | tail -n 1 >> difftranslations
  grep -C 1 'Common subdirectories:' $i | tail -n 1 >> difftranslations
  echo >> difftranslations
done

sed -i -e 's/%s/.*/g
s/\\\n"/$/' difftranslations

exit 0


