#!/bin/sh
# Created by Ryan Boren
# Later code and patches from
# Kimmo Suominen (more) and Nikolay Bachiyski (less)

TEMPLATE=crossreferences.pot
cwd=`pwd`
cd "/home/francesc/wpplug/cref/trunk" || exit 1

cp /dev/null "$cwd/$TEMPLATE"

find . -name '*.php' -print \
| sed -e 's,^\./,,' \
| sort \
| xargs xgettext \
    --keyword=__ \
    --keyword=_e \
    --keyword=_c \
	--keyword=__ngettext:1,2 \
	--keyword=__ngettext_noop:1,2 \
    --default-domain=wordpress \
    --language=php \
    --output="$cwd/$TEMPLATE" \
    --join-existing \
	--from-code utf-8 \
	--copyright-holder="Francesc Hervada-Sala" \
	--msgid-bugs-address=http://francesc.hervada.net/wordpress

cd "$cwd"

sed -i -e '1s/^# SOME DESCRIPTIVE TITLE/# WordPress Cross-References-Plugin POT file/' "$TEMPLATE"
# sub only the YEAR in the copyright message (the 2nd line)
sed -i -e '2s/YEAR/'`date +%Y`'/' "$TEMPLATE"
sed -i -e 's/\(^#.*\)PACKAGE\(.*\)/\1WordPress\2/g' "$TEMPLATE"

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