#!/bin/sh

# Use like this
#i18ndude rebuild-pot --pot ./GenericPloneContent.pot --merge ../i18n/generated.pot --exclude=`find ../profiles -name "*.*py"` --create schemamanager ../ || exit 1

rm ./rebuild_i18n.log

# Path to i18ndude
I18NDUDE=i18ndude

$I18NDUDE rebuild-pot --pot ./webcouturier.dropdownmenu.pot --create webcouturier.dropdownmenu ../ || exit 1
$I18NDUDE sync --pot ./webcouturier.dropdownmenu.pot ./*/LC_MESSAGES/webcouturier.dropdownmenu.po

$I18NDUDE rebuild-pot --pot ./plone.pot --create plone ../ || exit 1
$I18NDUDE sync --pot ./plone.pot ./*/LC_MESSAGES/plone.po

WARNINGS=`find . -name "*pt" | xargs $I18NDUDE find-untranslated | grep -e '^-WARN' | wc -l`
ERRORS=`find . -name "*pt" | xargs $I18NDUDE find-untranslated | grep -e '^-ERROR' | wc -l`
FATAL=`find . -name "*pt"  | xargs $I18NDUDE find-untranslated | grep -e '^-FATAL' | wc -l`

echo
echo "There are $ERRORS errors \(almost definitely missing i18n markup\)"
echo "There are $WARNINGS warnings \(possibly missing i18n markup\)"
echo "There are $FATAL fatal errors \(template could not be parsed, eg. if it\'s not html\)"
echo "For more details, run \'find . -name \"\*pt\" \| xargs i18ndude find-untranslated\' or" 
echo "Look the rebuild i18n log generate for this script called \'rebuild_i18n.log\' on locales dir "

touch ./rebuild_i18n.log

find ../ -name "*pt" | xargs $I18NDUDE find-untranslated > rebuild_i18n.log
find ../ -name "*.xml" | xargs $I18NDUDE find-untranslated >> rebuild_i18n.log
