#!/bin/sh -e
# git treeish for new po data (only use non-fuzzy)
NEW_TREEISH="$1"
# Directory holding po data based on debian-reference.en.xmlt (persistent)
DPO="po"
# The threshold should be 80 if translation is completed.
MSGCAT="/usr/bin/msgcat"
MSGATTRIB="/usr/bin/msgattrib"

set -x
cd ${DPO}
for f in *.po; do
  rm -f ${f}_orig
  rm -f ${f}_new
  cp ${f} ${f}_orig
  git checkout "${NEW_TREEISH}" $f
  ${MSGATTRIB} --translated -o ${f}_new ${f}
  rm -f ${f}
  # create po using only translated strings
  ${MSGCAT} -o ${f} --use-first ${f}_new ${f}_orig
  rm -f ${f}_orig
  rm -f ${f}_new
done
cd -
# make sure to have unstranslated strings in po files
make po
git add ${DPO}/*.po ${DPO}/*.pot

