#!/bin/sh

HELPDIR=$OOINSTDIR/help

if (! test -d $HELPDIR); then
    echo "Cannot find $HELPDIR; make sure you installed OOo first"
    exit 1;
fi

# the available extra localizations
LANGNUMS="07 33 34 36 39 42 43 46 49 81 82 86 88"

for LANGNUM in $LANGNUMS ; do
  LANGCODE=`$TOOLSDIR/bin/openoffice-xlate-lang -i $LANGNUM`
  install -m 755 -d $HELPDIR/$LANGCODE || exit 1;
  if test -f $SRCDIR/helpcontent_${LANGNUM}_unix.tar.bz2 ; then
    echo "Unpacking $LANGCODE help content..."
    tar -xjf $SRCDIR/helpcontent_${LANGNUM}_unix.tar.bz2 -C $HELPDIR/$LANGCODE || exit 1;
  
    pushd $HELPDIR/$LANGCODE
    for arch in *.zip ; do
      if test "z$arch" != "zhelpxsl.zip" ; then
        unzip -o $arch
      fi
      rm $arch
    done
    popd

    # fix or add highcontrast*.css
    for config in custom.css default.css \
	    highcontrastblack.css highcontrastwhite.css \
    	    highcontrast1.css highcontrast2.css ; do
      if test -f $HELPDIR/$LANGCODE/$config ; then
        $TOOLSDIR/bin/help-font-munge $HELPDIR/$LANGCODE/$config || exit 1;
	rm $HELPDIR/$LANGCODE/$config.bak
      else
        cp -a $HELPDIR/en/$config $HELPDIR/$LANGCODE/$config || exit 1;
      fi
    done
      
    # create list of common files and directories
    find $HELPDIR/$LANGCODE -type d -exec echo %dir {}/ \; >$BUILDDIR/help_${LANGCODE}_list.txt || exit 1;
    find $HELPDIR/$LANGCODE "(" -type f -or -type l ")" >>$BUILDDIR/help_${LANGCODE}_list.txt || exit 1;
  else
    echo "Warning: $LANGCODE help content is not available..."
    rm -f $BUILDDIR/help_${LANGCODE}_list.txt
  fi
done
