summaryrefslogtreecommitdiffstats
path: root/scripts/po4a-display-man
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 11:26:17 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 11:26:17 +0000
commit5df6c2aefebe3d2abcc939a88e294876d59f03ca (patch)
tree63fb332a0f21ddb91cb789c80cf64e134d373463 /scripts/po4a-display-man
parentInitial commit. (diff)
downloadpo4a-5df6c2aefebe3d2abcc939a88e294876d59f03ca.tar.xz
po4a-5df6c2aefebe3d2abcc939a88e294876d59f03ca.zip
Adding upstream version 0.72.upstream/0.72
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/po4a-display-man')
-rwxr-xr-xscripts/po4a-display-man149
1 files changed, 149 insertions, 0 deletions
diff --git a/scripts/po4a-display-man b/scripts/po4a-display-man
new file mode 100755
index 0000000..76dfe7b
--- /dev/null
+++ b/scripts/po4a-display-man
@@ -0,0 +1,149 @@
+#!/bin/sh
+#
+# po4a-display-man shows a translated manpage, recompiling everything on the fly with po4a.
+# Translators can see the effects of their work without reinstalling everything.
+#
+
+OPTIONS=""
+
+usage() {
+ echo "Usage: $0 -p PO_FILE [-m MASTER_FILE] [-o PO4A_OPT]"
+ return 0
+}
+
+error () {
+ echo "Error: $1" 1>&2
+ exit 1
+}
+
+while getopts m:p:ho: option
+do
+ case $option in
+ m)
+ MASTER="$OPTARG"
+ ;;
+ p)
+ PO="$OPTARG"
+ ;;
+ o)
+ OPTIONS="$OPTIONS $OPTARG"
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ [?])
+ usage 1>&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "$PO" ]
+then
+ usage 1>&2
+ exit 1
+fi
+
+if [ ! -f "$PO" ]
+then
+ error "could not find PO file: $PO"
+fi
+
+if [ -z "$MASTER" ]
+then
+ echo "No manpage specified."
+ echo "Trying to find the manpage according to a line reference in the PO."
+ MASTER=$(grep -m 1 "^#:" $PO | sed -e 's/^.* \(.*\):.*$/\1/')
+fi
+
+find_man()
+{
+ section="$1"
+ man="$2"
+ echo -n "Looking for manpage $file"
+ [ -n "$section" ] && echo " in section $section" || echo ""
+ MAN_NUMBER=`man --all --where --locale=C $section "$man" 2> /dev/null | wc -l`
+
+ if [ "$MAN_NUMBER" = "0" ]
+ then
+ return 1
+ elif [ "$MAN_NUMBER" != "1" ]; then
+ MAN_NUMBER=`man --all --where --locale=C $section "$man" 2> /dev/null | \
+ grep "\/$man\.$section\(.gz\)\?$" | wc -l`
+ if [ "$MAN_NUMBER" = "1" ]
+ then
+ MASTER=`man --where --locale=C "$section" "$man" | grep "\/$man\.$section\(.gz\)\?$"`
+ echo "Multiple manpages in section $section: $(man -aw -L C $section "$man"), only one exactly matches the section."
+ else
+ error "Too many possible manpages: $(man -aw -L C $section "$man"), you must specify the manpage or the section"
+ fi
+ else
+ MASTER=`man --where --locale=C "$section" "$man"`
+ fi
+
+ return 0
+}
+
+if [ ! -f "$MASTER" ]
+then
+ echo "Can't find the master man page $MASTER"
+ file=$(basename "$MASTER")
+ MASTER=""
+ section=""
+ if ! find_man "" "$file"
+ then
+ # Maybe $file contains a section
+ # (in the form of file.section.extension)
+ section=$(echo "$file" | sed -ne 's/^.*\.\([1-9].*\)$/\1/; s/\..*//; p')
+ file=$(echo "$file" | sed -e 's/\.[1-9].*//')
+ if ! find_man "$section" "$file"
+ then
+ # Maybe there is an extension at the end of the manpage (e.g. .man)
+ file=$(echo "$file" | sed -e 's/\..*//')
+ if ! find_man "$section" "$file"
+ then
+ echo "No manpage found"
+ echo "You must provide the manpage with the -m option"
+ MASTER=""
+ fi
+ fi
+ fi
+ if [ -n "$MASTER" ]
+ then
+ echo "Using: $MASTER as the original manpage"
+ fi
+fi
+
+# checking mandatory options
+if [ -z "$MASTER" ]
+then
+ usage 1>&2
+ exit 1
+fi
+
+# checking files
+if [ ! -e "$MASTER" ]
+then
+ error "could not find master file: $MASTER"
+fi
+
+
+if [ "${MASTER%.gz}" = "$MASTER" ]
+then
+ MAINNAME="$MASTER"
+else
+ MAINNAME=`mktemp`
+ trap "rm \"$MAINNAME\"" EXIT INT
+ gunzip -c "$MASTER" > "$MAINNAME"
+fi
+
+CHARSET_MASTER=`file -i "$MAINNAME" | cut -d "=" -f 2`
+CHARSET_PO=`file -i "$PO" | cut -d "=" -f 2`
+
+po4a-translate -f man -k 0 -m "$MAINNAME" -M "$CHARSET_MASTER" \
+ -p "$PO" $OPTIONS| iconv -f "$CHARSET_PO" -t // | man -l -
+
+# TODO: man may need some options (e.g. -L)
+# as we cannot detect what options are needed, they will have to be
+# specified on the po4a-display-man command line.