#!/bin/sh
if [ -z "$1" ]; then
 echo "USAGE: extract-plugin [pluginname]"
  exit 1
fi
date=`date +%Y%m%d`
install -d packages
plugin=$1


if [ -f po/plugins/${plugin}.pot ]; then
    prefix='plugins/'
fi

if [ -f po/extra/${plugin}.pot ]; then
    prefix='extra/'
fi

if [ -f po/${plugin}.pot ]; then
    prefix=''
else
    echo "No such plugin"
    exit
fi

# Compile locales
for trans in `ls locale/`; do
    if [ -f locale/${trans}/LC_MESSAGES/${prefix}${plugin}.po ]; then
	msgfmt locale/${trans}/LC_MESSAGES/${prefix}${plugin}.po \
	    -o locale/${trans}/LC_MESSAGES/${prefix}${plugin}.mo
    fi
done
# Build package
tar -cf packages/${plugin}-${date}.tar \
    locale/*/LC_MESSAGES/${prefix}${plugin}.po \
    locale/*/LC_MESSAGES/${prefix}${plugin}.mo \
    po/${prefix}${plugin}.pot install
zip -9 -q packages/${plugin}-${date}.zip \
    locale/*/LC_MESSAGES/${prefix}${plugin}.po \
    locale/*/LC_MESSAGES/${prefix}${plugin}.mo \
    po/${prefix}${plugin}.pot install
# Pack them
for package in `ls packages/*-${date}.tar`; do
    gzip -9 ${package} -c > ${package}.gz
    bzip2 ${package}
done
#
echo "Plugin translations are saved in packages directory"
