#!/bin/bash

function help () {
    echo "extract translations for a plugin:"
    echo "this script will create one .po file fo each dir existing"
    echo "insinde <plugindir>/i18n folder. Before run it ensure you"
    echo "have that folder created"
    echo ""
    echo "usage:"
    echo ""
    echo "$0 <plugindir>"
}

if [ ! $# -eq 1 ]
then
    help
else
    PLUGINDIR=$1
    FILES=$(find $PLUGINDIR -regex ".*py$")
    LANGUAGES=$(ls $PLUGINDIR/i18n)

    for i in $LANGUAGES
    do
        directory=$PLUGINDIR/i18n/$i/LC_MESSAGES
        if [ ! -d $directory ]; then mkdir $directory; fi
        if [ ! -f $directory/messages.po ]; then touch $directory/messages.po; fi
        xgettext -k_p -j -d messages -o $directory/messages.po --from-code=utf-8 -L Python $FILES $PLUGINDIR/templates/*.html
    done
fi
