Skip to content

Commit eb541c8

Browse files
authored
Improve remove_untranslated.sh (#190)
* Improve removal feedback * Do not silently fail and quit on invalid po file * Remove unnecessary trap statement * Initialize to_check array * one file per line to check
1 parent ef0192b commit eb541c8

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

scripts/remove_untranslated.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
# e.g.:
44
# remove_untranslated.sh cpython/Doc/locales
55

6-
set -ex
7-
8-
trap "rm -vf $po" 1 2 3 6
6+
set -o pipefail
97

108
if [ -n "$1" ]; then
11-
cd "$1"
9+
cd "$1" || exit 1
1210
fi
1311

1412
pofiles=$(find * -name '*.po' | sort)
13+
to_check=()
1514
to_remove=()
1615
for po in $pofiles; do
1716
output=$(LC_ALL=C /usr/bin/msgfmt -cvo /dev/null $po 2>&1 | grep -E '[0-9] translated message')
18-
if $(echo $output | grep '^0 translated messages' > /dev/null); then
17+
if [ $? -ne 0 ]; then
18+
echo "** msgfmt failed: $po"
19+
to_check+=($po)
20+
elif $(echo $output | grep '^0 translated messages' > /dev/null); then
21+
echo "Including to removal: $po"
1922
to_remove+=($po)
2023
fi
2124
done
@@ -24,5 +27,17 @@ done
2427
if [ ${#to_remove[@]} -eq 0 ]; then
2528
echo "No empty PO to remove."
2629
else
27-
git rm ${to_remove[@]}
30+
echo -n "Removing... "
31+
if rm ${to_remove[@]}; then
32+
echo "Done!"
33+
else
34+
echo "Failed!"
35+
fi
36+
fi
37+
38+
if [ ${#to_check[@]} -ne 0 ]; then
39+
echo "These PO files failed msgfmt (not removed, please check):"
40+
for file in "${to_check[@]}"; do
41+
echo "- ${file}"
42+
done
2843
fi

0 commit comments

Comments
 (0)