#!/bin/sh
# Based on theme-gettext created by Ryan Boren,
# Kimmo Suominen and Nikolay Bachiyski
# Modified into commentmailer-gettext by Huda Toriq

cwd=`pwd`
cd "$1" || exit 1

THEME_SLUG=`basename $1`
if [ -n "$2" ]; then THEME_SLUG="$2"; fi
TEMPLATE=commentmailer.pot

if [ -d ".svn" ]; then svn up; fi

cp /dev/null "$TEMPLATE"

find . -name '*.php' -print \
| sed -e 's,^\./,,' \
| sort \
| xargs xgettext \
    --keyword=__ \
    --keyword=_e \
    --keyword=_c \
	--keyword=__ngettext:1,2 \
    --default-domain=ym_status \
    --language=php \
    --output="$TEMPLATE" \
    --join-existing \
	--from-code utf-8 \
	--copyright-holder="Huda Toriq" \
	--msgid-bugs-address=hudatoriq@gmail.com


sed -i -e "1s/^# SOME DESCRIPTIVE TITLE/# CommentMailer pot file/" "$TEMPLATE"
# substitute only the YEAR in the copyright message (the 2nd line)
sed -i -e '2s/YEAR/'`date +%Y`'/' "$TEMPLATE"
sed -i -e "s/\(^#.*\)PACKAGE\(.*\)/\1CommentMailer plugin\2/g" "$TEMPLATE"

# and the cherry of the pie - extract version using magic - versoextracanus!~
VERSION=`fgrep -m 1 -i 'Version:' commentmailer.php | cut -d ' ' -f 2`
sed -i -e "s/\(Project-Id-Version: \)PACKAGE VERSION/\1$VERSION/" "$TEMPLATE"
