| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# FIXME stolen from gnome-control-center, GPLv2 |
| 4 |
# This project is LGPLv2 |
| 5 |
# https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/2269#note_2079291 |
| 6 |
|
| 7 |
srcdirs="src document-portal" |
| 8 |
uidirs=$srcdirs |
| 9 |
desktopdirs=$srcdirs |
| 10 |
policydirs=$srcdirs |
| 11 |
xmldirs=$srcdirs |
| 12 |
|
| 13 |
# find source files that contain gettext functions with literal or GETTEXT_PACKAGE argument |
| 14 |
files=$(grep -lRs --include='*.c' 'gettext *(\("\|GETTEXT_PACKAGE,\)' $srcdirs) |
| 15 |
|
| 16 |
# find source files that contain gettext macros |
| 17 |
files="$files "$(grep -lRs --include='*.c' --include='*.h' '[^I_)]_(' $srcdirs) |
| 18 |
|
| 19 |
# find ui files that contain translatable string |
| 20 |
files="$files "$(grep -lRis --include='*.ui' 'translatable="[ty1]' $uidirs) |
| 21 |
|
| 22 |
# find .desktop files |
| 23 |
files="$files "$(find $desktopdirs -name '*.desktop*') |
| 24 |
|
| 25 |
# find .policy files |
| 26 |
files="$files "$(find $policydirs -name '*.policy*') |
| 27 |
|
| 28 |
# find .xml.in and .gschema.xml files |
| 29 |
files="$files "$(find $xmldirs -not -name '*.gresource.xml*' \ |
| 30 |
-name '*.xml.in*' -o \ |
| 31 |
-name '*.gschema.xml') |
| 32 |
|
| 33 |
# filter out excluded files |
| 34 |
if [ -f po/POTFILES.skip ]; then |
| 35 |
files=$(for f in $files; do |
| 36 |
! grep -q "^$f" po/POTFILES.skip && echo "$f" |
| 37 |
done) |
| 38 |
fi |
| 39 |
|
| 40 |
# find those that aren't listed in POTFILES.in |
| 41 |
missing=$(for f in $files; do |
| 42 |
! grep -q "^$f" po/POTFILES.in && echo "$f" |
| 43 |
done) |
| 44 |
|
| 45 |
# find those that are listed in POTFILES.in but do not contain translatable strings |
| 46 |
invalid=$(while IFS= read -r f; do |
| 47 |
! grep -q "$f" <<< "$files" && echo "$f" |
| 48 |
done < <(grep '^[^#]' po/POTFILES.in)) |
| 49 |
|
| 50 |
# find out if POTFILES.in is sorted correctly, ignoring empty lines |
| 51 |
sorted=$(grep '^[^#]' po/POTFILES.in | \ |
| 52 |
LC_ALL=en_US.UTF-8 sort -cu 2>&1 >/dev/null | \ |
| 53 |
awk -F ': *' '{print $5}') |
| 54 |
|
| 55 |
if [ ${#missing} -eq 0 ] && [ ${#invalid} -eq 0 ] && [ ${#sorted} -eq 0 ]; then |
| 56 |
exit 0 |
| 57 |
fi |
| 58 |
|
| 59 |
if [ ${#missing} -ne 0 ]; then |
| 60 |
cat >&2 << EOT |
| 61 |
|
| 62 |
The following files are missing from po/POTFILES.in or po/POTFILES.skip: |
| 63 |
|
| 64 |
EOT |
| 65 |
for f in $missing; do |
| 66 |
echo " $f" >&2 |
| 67 |
done |
| 68 |
fi |
| 69 |
|
| 70 |
if [ ${#invalid} -ne 0 ]; then |
| 71 |
cat >&2 << EOT |
| 72 |
|
| 73 |
The following files are in po/POTFILES.in but are missing or not translatable: |
| 74 |
|
| 75 |
EOT |
| 76 |
for f in $invalid; do |
| 77 |
echo " $f" >&2 |
| 78 |
done |
| 79 |
fi |
| 80 |
|
| 81 |
if [ ${#sorted} -ne 0 ]; then |
| 82 |
cat >&2 << EOT |
| 83 |
|
| 84 |
The following file is not sorted properly in po/POTFILES.in: |
| 85 |
|
| 86 |
EOT |
| 87 |
echo " $sorted" >&2 |
| 88 |
fi |
| 89 |
|
| 90 |
echo >&2 |
| 91 |
|
| 92 |
exit 1 |