#!/bin/sh
# Didier Spaier 2016
if [ $UID -eq 0 ]; then
  echo "Please execute this script as a regular user, not as root."
  exit
fi
ROOT=`dirname "$0"`
TMP=$(mktemp -d) || exit 1
export TEXTDOMAIN=slint
. gettext.sh
#
Localization() {
REPLY=dummy
while [ ! -z $REPLY ]; do
    dialog --title "`gettext " Internationalization and localization of shell scripts "`" --menu \
    "`gettext "Which document would you like to read?

Press 'Cancel' to return to the main menu."`" 0 0 6 \
    "1_PRESENTATION" "`gettext "General presentation"`" \
    "2_DIAGRAMS" "`gettext "Processes diagrams"`" \
    "3_INTERNATIONALIZATION" "`gettext "Internationalization process"`" \
    "4_LOCALIZATION" "`gettext "Localization, usage and maintenance processes"`" \
    "5_MAINTAINERS" "`gettext "Recommendations for developpers and maintainers"`" \
    "6_TRANSLATORS" "`gettext "Recommendations for translators"`" \
    2>$TMP/reply
    REPLY="$(cat $TMP/reply)"
    rm -f $TMP/reply
    if [ ! -z $REPLY ]; then
      most $ROOT/$REPLY
    fi
done
REPLY=dummy
}
Persian() {
REPLY=dummy
while [ ! -z $REPLY ]; do
    dialog --title "`gettext " How to display man pages in Persian "`" --menu \
    "`gettext "this document is available in English and Persian, in \
Portable Document format and in Open Document Format.

Press 'Cancel' to return to the main menu."`" 0 0 4 \
    "man_en.odt" "`gettext "How to in English (Open Document)"`" \
    "man_en.pdf" "`gettext "How to in English (Portable Document)"`" \
    "man_fa.odt" "`gettext "How to in Persian (Open Document)"`" \
    "man_fa.pdf" "`gettext "How to in Persian (Portable Document)"`" \
    2>$TMP/reply
    REPLY="$(cat $TMP/reply)"
    rm -f $TMP/reply
    if [ ! -z $REPLY ]; then
		if [ "${REPLY%pdf}" = "$REPLY" ]; then
			if [ "$(which soffice)" = "/usr/bin/soffice" ]; then
				/usr/bin/soffice $ROOT/$REPLY & 1>/dev/null 2>/dev/null
			elif [ "$(which calligrawords)" = "/usr/bin/calligrawords" ]; then
				/usr/bin/calligrawords $ROOT/$REPLY & 1>/dev/null 2>/dev/null
			fi			   
		fi
		if [ "${REPLY%odt}" = "$REPLY" ]; then
			if [ "$(which acroread)" = "/usr/bin/acroread" ]; then
				/usr/bin/acroread $ROOT/$REPLY & 1>/dev/null 2>/dev/null
			elif [ "$(which atril)" = "/usr/bin/atril" ]; then
				/usr/bin/atril $ROOT/$REPLY & 1>/dev/null 2>/dev/null			   
			elif [ "$(which evince)" = "/usr/bin/evince" ]; then
				/usr/bin/evince $ROOT/$REPLY & 1>/dev/null 2>/dev/null
			elif [ "$(which xpdf)" = "/usr/bin/xpdf" ]; then
				/usr/bin/xpdf $ROOT/$REPLY & 1>/dev/null 2>/dev/null
			fi		   
		fi
    fi
done
REPLY=dummy
}
REPLY=dummy
while [ ! -z $REPLY ]; do
    dialog --title "`gettext " Slint documentation "`" --menu \
    "`gettext "Which document would you like to read?"`" 0 0 5 \
    "AboutSlint" "`gettext "Presentation of the Slint project"`" \
    "StartupGuide" "`gettext "Help for new Slint users"`" \
    "README_BRLTTY" "`gettext "Install and use Slint with a screen reader"`" \
    "Localization" "`gettext ">> How-to localize shell scrips (sub-menu)"`" \
    "Persian" "`gettext ">> How-to display man pages in Persian (sub-menu)"`" \
    2>$TMP/reply
    REPLY="$(cat $TMP/reply)"
    rm -f $TMP/reply
    if [ ! -z $REPLY ]; then
        if [ "$REPLY" = "AboutSlint" ] || \
        [ "$REPLY" = "README_BRLTTY" ] || \
        [ "$REPLY" = "StartupGuide" ]; then
			most $ROOT/$REPLY
		else
		    $REPLY
		fi
	  
    fi
done
rm -rf $TMP

