Debian Codegraph @

utils/instpo.sh

raw
1 #!/bin/sh
2 #
3 # Copyright 2025 Brad Lanam Pleasant Hill CA
4 #
5
6 BUILDDIR=$1
7 PODIR=$2
8 INST_LOCALEDIR=$3
9 TMPPODIR=$4
10
11 DEST_LOCALEDIR="${DESTDIR}${INST_LOCALEDIR}"
12
13 if [ "x${BUILDDIR}" = x ]; then
14 echo "instpo.sh: No build dir specified"
15 exit 1
16 fi
17
18 if [ ! -f "${BUILDDIR}/diconfig.h" ]; then
19 echo "instpo.sh: Could not locate diconfig.h"
20 exit 1
21 fi
22
23 # diconfig.h:
24 # #define _enable_nls 1
25 grep -l '^#define _enable_nls 1' ${BUILDDIR}/diconfig.h >/dev/null 2>&1
26 rc=$?
27 if [ $rc -ne 0 ]; then
28 exit 0
29 fi
30
31 if [ "x${PODIR}" = x ]; then
32 echo "instpo.sh: No po/ dir specified"
33 exit 1
34 fi
35
36 if [ ! -d "${PODIR}" ]; then
37 echo "instpo.sh: po/ dir does not exist"
38 exit 1
39 fi
40
41 if [ "x${INST_LOCALEDIR}" = x ]; then
42 echo "instpo.sh: No locale dir specified"
43 exit 1
44 fi
45
46 if [ "x${TMPPODIR}" = x ]; then
47 echo "instpo.sh: No temporary dir specified"
48 exit 1
49 fi
50
51 msgfmtcmd=`which gmsgfmt 2>/dev/null`
52 rc=$?
53 if [ $rc -ne 0 -o "x$msgfmtcmd" = x ]; then
54 msgfmtcmd=`which msgfmt 2>/dev/null`
55 rc=$?
56 if [ $rc -ne 0 -o "x$msgfmtcmd" = x ]; then
57 # maybe the which command is not there...
58 # try some common spots
59 if [ "x$msgfmtcmd" = x -a -f /usr/bin/msgfmt ]; then
60 msgfmtcmd=/usr/bin/msgfmt
61 fi
62 if [ "x$msgfmtcmd" = x -a -f /opt/local/bin/msgfmt ]; then
63 msgfmtcmd=/opt/local/bin/msgfmt
64 fi
65 if [ "x$msgfmtcmd" = x -a -f /opt/homebrew/bin/msgfmt ]; then
66 msgfmtcmd=/opt/homebrew/bin/msgfmt
67 fi
68 if [ "x$msgfmtcmd" = x -a -f /usr/local/bin/msgfmt ]; then
69 msgfmtcmd=/usr/local/bin/msgfmt
70 fi
71 fi
72 fi
73
74 if [ "x$msgfmtcmd" = x ]; then
75 echo "instpo.sh: Unable to locate msgfmt command"
76 exit 1
77 fi
78
79 cd "${PODIR}"
80 rc=$?
81 if [ $rc -ne 0 ]; then
82 echo "No po/ directory."
83 exit 0
84 fi
85
86 test -d "${DEST_LOCALEDIR}" || mkdir -p "${DEST_LOCALEDIR}"
87 test -d "${TMPPODIR}" || mkdir -p "${TMPPODIR}"
88
89 for i in *.po; do
90 j=`echo $i | sed 's,\\.po$,,'`
91 ${msgfmtcmd} -o "${TMPPODIR}/$j.mo" $i 2> /dev/null
92 rc=$?
93 if [ $rc -ne 0 ]; then
94 echo "instpo.sh: msgfmt failed for $i"
95 continue
96 fi
97 if [ ! -f "${TMPPODIR}/$j.mo" ]; then
98 continue
99 fi
100 test -d "${DEST_LOCALEDIR}/$j/LC_MESSAGES" ||
101 mkdir -p "${DEST_LOCALEDIR}/$j/LC_MESSAGES"
102 cp -pf "${TMPPODIR}/$j.mo" "${DEST_LOCALEDIR}/$j/LC_MESSAGES/di.mo"
103 rm -f "${TMPPODIR}/$j.mo"
104 echo "-- Installing: ${DEST_LOCALEDIR}/$j/LC_MESSAGES/di.mo"
105 done
106
107 exit 0