File: check_localized_cheatsheets.sh

package info (click to toggle)
postgis 3.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 70,052 kB
  • sloc: ansic: 162,204; sql: 93,950; xml: 53,121; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,434; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (42 lines) | stat: -rwxr-xr-x 1,152 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

VERBOSE=0
if [ "$1" = "-v" ]; then
  VERBOSE=1
  shift
fi

test -n "$3" || {
  echo "Usage: $0 [-v] <source_file> <source_lang> <target_lang> [<target_lang> ...]" >&2
  exit 1
};

SOURCE_FILE="$1"
shift
SOURCE_LANG="$1"
shift
TARGET_LANGS="$@"

test -e "${SOURCE_FILE}" || {
  echo "No such file or directory: ${SOURCE_FILE}" >&2
  exit 1
}

# Read sup tags from source language cheatsheet
for tag in $(xmllint --html --xpath '/html/body/span/sup/text()' "${SOURCE_FILE}"); do
  count=$(grep -c "<sup> *$tag *</sup>" "${SOURCE_FILE}")
  [ "$VERBOSE" = 1 ] && echo "Occurrences of tag $tag in source file: $count"
  for lang in ${TARGET_LANGS}; do
    TR_FILE=$(echo "${SOURCE_FILE}" | sed "s/-${SOURCE_LANG}/-${lang}/");
    test -e "${TR_FILE}" || {
      echo "No such file or directory: ${TR_FILE}" >&2
      exit 1
    }
    count_lang=$(grep -c "<sup> *$tag *</sup>" "${TR_FILE}")
    [ "$VERBOSE" = 1 ] && echo "Occurrences of tag $tag in $lang file: $count_lang"
    if [ $count_lang != $count ]; then
      echo "Tag $tag occurs $count times in ${SOURCE_FILE} and $count_lang times in ${TR_FILE}" >&2
      exit 1
    fi
  done
done