/usr/bin/potooledit is in potool 0.16-2+b1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #!/bin/bash
# Copyright (C) 2000-2012 Marcin Owsiany <porridge@debian.org>
#
# Set up temporary directory
#
POTMP=`mktemp -d -t poedit.XXXXXX` || exit 1
function usage()
{
echo "Usage: poedit [ -a ] [ -p ] [ -n ] <file.po>" >&2
exit 1
}
#
# Check what msgs to include
#
INCLUDE_ALL_MSGS=no
IGNORE_ENCODING=no
PRESERVE_WRAPPING=no
TEMP=`getopt -o anp -n 'poedit' -- "$@"`
if [ $? != 0 ] ; then usage ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true ; do
case "$1" in
-a)
INCLUDE_ALL_MSGS=yes
shift
;;
-n)
IGNORE_ENCODING=yes
shift
;;
-p)
PRESERVE_WRAPPING=yes
shift
;;
--)
shift
break
;;
*)
echo "Internal error!" >&2
exit 1
;;
esac
done
POFILE="$1"
TMPFILE="$POTMP/`basename -- "$POFILE"`"
TMPFILE2="$TMPFILE.tmp"
#
# Some sanity checks
#
[ -z "$POFILE" ] && usage
if ! [ -w "$POFILE" ]; then
echo "$POFILE: not writable" >&2
exit 1
fi
if [ -n "$EDITOR" ]; then
EDITCMD="$EDITOR"
elif which sensible-editor >/dev/null 2>&1; then
EDITCMD="sensible-editor"
else
echo '$EDITOR is not set, and sensible-editor is not available' >&2
exit 1
fi
if [ $PRESERVE_WRAPPING = yes ]; then
potool="potool -p"
else
potool="potool"
fi
#
# Get file encoding
#
if [ $IGNORE_ENCODING = no ] ; then
input_encoding=$($potool -ft -fnth "$POFILE" | egrep -m 1 -i '^"Content-Type:' | perl -p -e 's,^.*charset=(.*?)( *;.*)?\\n"$,$1,')
if [ -z "$input_encoding" ] ; then
echo "Failed to retrieve encoding from the content-type header." 1>&2
echo "Make sure the file has a proper header before running $0" 1>&2
exit 1
fi
locale_encoding=$(locale charmap)
if [ -z "$locale_encoding" ] ; then
echo "Failed to retrieve the locale charmap. Something is very wrong." 1>&2
exit 1
fi
fi
#
# Filter the file
#
if [ "$INCLUDE_ALL_MSGS" = "yes" ]
then
$potool "$POFILE" -ft -fno > "$TMPFILE" || { echo "Running '$potool \"$POFILE\" -ft -fno > \"$TMPFILE\"' failed with code $?" >&2; exit 1; }
echo >> "$TMPFILE"
$potool "$POFILE" -fnt >> "$TMPFILE" || { echo "Running '$potool \"$POFILE\" -fnt >> \"$TMPFILE\"' failed with code $?" >&2; exit 1; }
echo >> "$TMPFILE"
$potool "$POFILE" -ft -fo >> "$TMPFILE" || { echo "Running '$potool \"$POFILE\" -ft -fo >> \"$TMPFILE\"' failed with code $?" >&2; exit 1; }
else
$potool "$POFILE" -fnth > "$TMPFILE" || { echo "Running '$potool \"$POFILE\" -fnth > \"$TMPFILE\"' failed with code $?" >&2; exit 1; }
fi
if [ $IGNORE_ENCODING = no ] ; then
#
# Recode the file so it is in the locale's encoding
#
iconv -f "$input_encoding" -t "$locale_encoding" < "$TMPFILE" > "$TMPFILE2"
if [ $? -ne 0 ]; then
echo "Recoding from [$input_encoding] to [$locale_encoding] failed." 1>&2
echo "Temp. file: $TMPFILE" 1>&2
exit 1
fi
#
# Fix the charset information
#
change-po-charset "$locale_encoding" "$TMPFILE2" > "$TMPFILE"
if [ $? -ne 0 ]; then
echo "Failed to substitute the encoding attribute in the header." 1>&2
echo "Make sure the file has a proper header before running $0" 1>&2
echo "Temp. file: $TMPFILE2" 1>&2
exit 1
fi
fi
#
# Run editor and update the file on success
#
$EDITCMD "$TMPFILE"
editor_ret="$?"
if [ $editor_ret -ne 0 ]; then
echo "$EDITCMD exited abnormally (code $editor_ret), not updating the po file" 1>&2
exit 1
fi
if [ $IGNORE_ENCODING = no ] ; then
#
# Change the charset information back
#
change-po-charset "$input_encoding" "$TMPFILE" > "$TMPFILE2"
if [ $? -ne 0 ]; then
echo "Failed to substitute the encoding attribute in the header." 1>&2
echo "Temp. file: " $TMPFILE 1>&2
exit 1
fi
#
# Recode the file back to the original encoding
#
iconv -f "$locale_encoding" -t "$input_encoding" < "$TMPFILE2" > "$TMPFILE"
if [ $? -ne 0 ]; then
echo "Recoding back from [$locale_encoding] to [$input_encoding] failed." 1>&2
echo "Temp. file: " $TMPFILE2 1>&2
exit 1
fi
fi
mv "$POFILE" "$POFILE~" || { echo "Failed to rename \"$POFILE\" to \"$POFILE~\""; exit 1; }
$potool "$POFILE~" "$TMPFILE" > "$POFILE"
if [ $? -eq 0 ]; then
printf "Before: %s/%s\n" `$potool -ft -s "$POFILE~"` `$potool -s "$POFILE~"`
printf "After: %s/%s\n" `$potool -ft -s "$POFILE"` `$potool -s "$POFILE"`
rm -f "$POFILE~" "$TMPFILE"
else
mv -f "$POFILE~" "$POFILE"
echo "Merging $POFILE with $TMPFILE failed" >&2
exit 1
fi
rm -Rf "$POTMP"
|