github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/update-pot (about) 1 #!/bin/sh 2 # -*- Mode: sh; indent-tabs-mode: t -*- 3 4 set -eu 5 6 # In LP#1758684 we got reports that the pot file generation 7 # is broken. To get to the bottom of this add checks here 8 # so that we error the build if this happens. Note that the 9 # strings may be update if those change but spread tests will 10 # tell us when it is needed. 11 check_canaries() { 12 c1="Alternative command to run" 13 c2="Name of the key to use, otherwise use the default key" 14 c3="too many arguments for command" 15 c4="%d days ago, at 15:04 MST" 16 17 for canary in "$c1" "$c2" "$c3" "$c4"; do 18 if ! grep -q "$canary" "$OUTPUT"; then 19 echo "canary '$canary' not found, pot extraction broken" 20 ls -lh "$OUTPUT" 21 exit 1 22 fi 23 done 24 } 25 26 HERE="$(readlink -f "$(dirname "$0")")" 27 28 OUTPUT="$HERE/po/snappy.pot" 29 if [ -n "${1:-}" ]; then 30 OUTPUT="$1" 31 fi 32 33 # ensure we have our xgettext-go 34 go install github.com/snapcore/snapd/i18n/xgettext-go 35 36 tmpdir="$(mktemp -d)" 37 trap 'rm -rf "$tmpdir"' EXIT 38 39 # exclude vendor and _build subdir 40 find "$HERE" -type d \( -name "vendor" -o -name "_build" -o -name ".git" \) -prune -o -name "*.go" -type f -printf "%P\n" > "$tmpdir/go.files" 41 42 "${GOPATH%%:*}/bin/xgettext-go" \ 43 -f "$tmpdir/go.files" \ 44 -D "$HERE" \ 45 -o "$OUTPUT" \ 46 --add-comments-tag=TRANSLATORS: \ 47 --sort-output \ 48 --package-name=snappy\ 49 --msgid-bugs-address=snappy-devel@lists.ubuntu.com \ 50 --keyword=i18n.G \ 51 --keyword-plural=i18n.NG 52 53 # check canary 54 check_canaries 55 56 sed -i 's/charset=CHARSET/charset=UTF-8/' "$OUTPUT" 57 58 find "$HERE" -path "$HERE/data/desktop/*.desktop.in" -type f -printf "%P\n" > "$tmpdir/desktop.files" 59 # we need the || true because Ubuntu 14.04's xgettext does not support 60 # extracting from desktop files. 61 xgettext \ 62 -f "$tmpdir/desktop.files" \ 63 -D "$HERE" \ 64 -o "$OUTPUT" \ 65 --language=Desktop \ 66 --sort-output \ 67 --package-name=snappy \ 68 --msgid-bugs-address=snappy-devel@lists.ubuntu.com \ 69 --join-existing || true 70 71 find "$HERE" -path "$HERE/data/polkit/*.policy" -type f -printf "%P\n" > "$tmpdir/polkit.files" 72 # we need the || true because of 73 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891347 74 xgettext \ 75 -f "$tmpdir/polkit.files" \ 76 -D "$HERE" \ 77 -o "$OUTPUT" \ 78 --its="$HERE/po/its/polkit.its" \ 79 --sort-output \ 80 --package-name=snappy \ 81 --msgid-bugs-address=snappy-devel@lists.ubuntu.com \ 82 --join-existing || true 83 84 check_canaries 85 86 # language packs 87 for p in "${HERE}"/po/*.po; do 88 lang=$(basename "$p" .po) 89 mkdir -p "$HERE/share/locale/$lang/LC_MESSAGES" 90 msgfmt -v -o "$HERE/share/locale/$lang/LC_MESSAGES/snappy.mo" "$p" 91 done