#! /bin/sh

# Test 'I' format directive flag.

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

tmpfiles="$tmpfiles fc5.tmp fc5.pot"
: ${XGETTEXT=xgettext}
${XGETTEXT} -o fc5.tmp --omit-header --no-location "${top_srcdir}/tests/format-c-5-prg.c" || exit 1
LC_ALL=C tr -d '\r' < fc5.tmp > fc5.pot || exit 1

tmpfiles="$tmpfiles fc5.ok"
cat <<EOF > fc5.ok
#, c-format
msgid "father of %d children"
msgstr ""
EOF

: ${DIFF=diff -b}
${DIFF} fc5.ok fc5.pot || exit 1

tmpfiles="$tmpfiles fc5-fa.po"
# This should better be Farsi, not German. Can some translator help me?
cat <<EOF > fc5-fa.po
#, c-format
msgid "father of %d children"
msgstr "Vater von %Id Kindern"
EOF

tmpfiles="$tmpfiles fc5-dir"
test -d fc5-dir || mkdir fc5-dir
test -d fc5-dir/fa || mkdir fc5-dir/fa
test -d fc5-dir/fa/LC_MESSAGES || mkdir fc5-dir/fa/LC_MESSAGES

: ${MSGFMT=msgfmt}
${MSGFMT} -o fc5-dir/fa/LC_MESSAGES/fc5.mo fc5-fa.po

tmpfiles="$tmpfiles fc5-fa.po.tmp fc5-fa.po.un"
: ${MSGUNFMT=msgunfmt}
${MSGUNFMT} -o fc5-fa.po.tmp fc5-dir/fa/LC_MESSAGES/fc5.mo || exit 1
LC_ALL=C tr -d '\r' < fc5-fa.po.tmp > fc5-fa.po.un || exit 1

: ${DIFF=diff -b}
${DIFF} fc5-fa.po fc5-fa.po.un || exit 1

LANGUAGE= ./fc5 fa_IR
case $? in
  0) ;;
  77)
    if test -f /usr/bin/localedef; then
      echo "Skipping test: locale fa_IR not installed"
    else
      echo "Skipping test: locale fa_IR not supported"
    fi
    rm -fr $tmpfiles; exit 77;;
  *) exit 1;;
esac

rm -fr $tmpfiles

exit 0
