~widelands-dev/widelands/bug-1656671

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
#!/bin/bash

## This script will validate all po files, using the i18nspector and
## translate-toolkit packages.

# Exit as soon as any line in the bash script fails.
set -e

# Move up if we're not in the base directory.
if [ -d "../utils" ]; then
  pushd ..
fi

# Double-check that we're in the correct directory.
if [ ! -f "utils/buildcat.py" -o ! -f "utils/remove_lf_in_translations.py" ]; then
  echo "Unable to find 'utils/buildcat.py' or 'utils/remove_lf_in_translations.py'."
  echo "Make sure you start this script from Widelands' base or utils directory.";
  exit 1;
fi

# Make sure that the output directory is there
if [ ! -d "po_validation" ]; then
  echo "Creating directory 'po_validation'"
  mkdir po_validation
fi

echo "Running i18nspector. This can take a while."

# We want a log of all errors.
i18nspector po/*/*.po \
  | grep "E:" \
  > po_validation/i18nspector-errors.log

# We don't care about all warnings, so we filter some out.
i18nspector po/*/*.po \
  | grep "W:" \
  | grep -v "invalid-last-translator" \
  | grep -v boilerplate \
  > po_validation/i18nspector-warnings.log


# Takes type of check as an argument.
# Makes a subdirectory for the argument if necessary,
# then runs pofilter with the check.
function run_pofilter() {
  if [ ! -d "po_validation/$1/" ]; then
    mkdir po_validation/$1/
  fi
  echo "Running pofilter for '$1'"
  pofilter -t $1 -i po/ -o po_validation/$1/
}

# These checks are critical
run_pofilter "printf"
run_pofilter "nplurals"

# These checks are important
run_pofilter "emails"
run_pofilter "filepaths"
run_pofilter "validchars"
run_pofilter "variables"
run_pofilter "urls"

# These checks are nice to have
run_pofilter "doublespacing"
run_pofilter "startwhitespace"
run_pofilter "endwhitespace"
run_pofilter "startpunc"
run_pofilter "endpunc"
run_pofilter "startcaps"
run_pofilter "numbers"

# We only run the options check on the command line help
if [ ! -d "po_validation/options/" ]; then
  echo "Creating directory 'options'"
  mkdir po_validation/options/
fi
echo "Running pofilter for 'options'"
pofilter -t options -i po/widelands_console/ -o po_validation/options/

echo "Cleaning up empty directories"
for dir in po_validation/*/
do
  dir=${dir%*/}
  echo "- Cleaning up ${dir##*/}"
    if [ ! "$(find po_validation/${dir##*/}/ -mindepth 1 -maxdepth 1 -type d -printf . | wc -c)" -eq 0 ]; then
    for subdir in po_validation/${dir##*/}/*/
    do
      subdir=${subdir%*/}
      if [ ! "$(ls -A po_validation/${dir##*/}/${subdir##*/})" ]; then
        rmdir po_validation/${dir##*/}/${subdir##*/}
      fi
    done
  fi
  if [ ! "$(ls -A po_validation/${dir##*/})" ]; then
    rmdir po_validation/${dir##*/}
  fi
done

echo "Done"