#!/bin/sh

# This script regenerates main POT file
#
# Environment variables that are used by script:
#    SM_STABLE_PATH (required) - path to SquirrelMail stable cvs
#    SM_DEVEL_PATH (required) - path to SquirrelMail devel cvs
#    SM_LOCALES_PATH (required) - path to SquirrelMail locales HEAD cvs
#    SM_DEBUG (optional) - if set, script does not remove string locations from pot
#                          WARNING: don't commit pot with locations into cvs.
#    SM_LANG_C (optional) - if set, xgettext uses -C option instead of -L php.
#
# Philipe Mingo <mingo@rotedic.com>
# Tomas Kuliavas <tokul@users.sourceforge.net>
#
#  $Id: xgetpo 14478 2015-01-03 03:48:43Z pdontthink $

message="You must set SM_STABLE_PATH; SM_DEVEL_PATH and SM_LOCALES_PATH before running this script"

# force use of same locale in order to keep same sorting order
LC_ALL=en_US.ISO8859-1
LANG=en_US.ISO8859-1
export LC_ALL LANG

# set common gettext options
XGETTEXT_OPTIONS="--keyword=_ -keyword=N_ --keyword=ngettext:1,2 --default-domain=squirrelmail --add-comments=i18n" ;

# Allows extraction with file names
if [ ! $SM_DEBUG ] ; then
    XGETTEXT_OPTIONS="${XGETTEXT_OPTIONS} --no-location";
fi

# Allows controlling language option
# (gettext v.0.10.40 = -C, gettext 0.11+ = -L php).
if [ $SM_LANG_C ] ; then
    XGETTEXT_OPTIONS="${XGETTEXT_OPTIONS} -C";
else
    XGETTEXT_OPTIONS="${XGETTEXT_OPTIONS} -L php";
fi

if [ ! ${SM_STABLE_PATH} ] ;
    then
	echo $message ;
	echo "SM_STABLE_PATH is not set" ;
	exit 1
fi

if [ ! ${SM_DEVEL_PATH} ] ;
    then
	echo $message ;
	echo "SM_DEVEL_PATH is not set" ;
	exit 1
fi

if [ ! ${SM_LOCALES_PATH} ];
    then
	echo $message ;
	echo "SM_LOCALES_PATH is not set" ;
	exit 1
fi

#  Stable core strings.

xgettext ${XGETTEXT_OPTIONS} \
    ${SM_STABLE_PATH}/src/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/class/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/class/*/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/functions/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/include/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/include/options/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

#  Stable plugins.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/administrator/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/bug_report/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/calendar/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/delete_move_next/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/filters/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/fortune/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/info/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/listcommands/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/mail_fetch/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/message_details/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/newmail/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/sent_subfolders/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/spamcop/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/squirrelspell/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/squirrelspell/modules/*.mod --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/plugins/translate/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# Stable independent strings.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_STABLE_PATH}/po/independent_strings.txt --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

#  Devel core strings.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/src/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/class/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/class/*/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/functions/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/functions/template/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/images/themes/*/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/include/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/include/options/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# Devel plugins.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/administrator/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/bug_report/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/bug_report/templates/default/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/calendar/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/change_password/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/change_password/backend/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/filters/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/fortune/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/info/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/listcommands/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/listcommands/templates/default/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/mail_fetch/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/message_details/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/newmail/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/preview_pane/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/sent_subfolders/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/spamcop/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/squirrelspell/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/squirrelspell/class/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/squirrelspell/modules/*.mod --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/plugins/translate/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# Devel templates.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/templates/*.php --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/templates/default/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/templates/default/plugins/fortune/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/templates/default/plugins/listcommands/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot
xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/templates/default_advanced/*.tpl --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# Devel independent strings.

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_DEVEL_PATH}/po/independent_strings.txt --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# Independent strings

xgettext ${XGETTEXT_OPTIONS} -j \
    ${SM_LOCALES_PATH}/independent_strings.txt --output=${SM_LOCALES_PATH}/po/squirrelmail.pot

# print stats
msgfmt --statistics ${SM_LOCALES_PATH}/po/squirrelmail.pot -o /dev/null
