Skip to content

Commit f104651

Browse files
committed
add syntax check for po files (multiline-strings, TGIs)
1 parent 2c2163e commit f104651

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

.github/workflows/scala.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
steps:
3636
- uses: actions/checkout@v3
37+
- name: Check PO/POT syntax
38+
run: sh src/scripts/syntax-check-po.sh
3739
- name: Check RUL2 syntax
3840
run: sh src/scripts/syntax-check-rul2.sh

src/scripts/syntax-check-po.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#
3+
# This script checks all the po/pot files for correct multi-line format and uppercased TGIs.
4+
# If any issues are found, they are printed to stdout and the script exits with a non-zero return code.
5+
set -e
6+
7+
INDIR="./ltext"
8+
OUT="./syntax-check-po.log"
9+
10+
sorted_input_files() {
11+
find -L "$INDIR" -type f \( -name '*.po' -o -name '*.pot' \) -print0 | sort -z
12+
}
13+
14+
strip_comments_and_whitespace() {
15+
${1:+ xargs -0} sed -e 's/^#.*//' -e 's/\s\+$//g' -e '/^\s*$/d'
16+
}
17+
# Note that we used sed and tail for concatenation which handle missing
18+
# newlines at the end of input files gracefully (unlike cat).
19+
20+
strip_valid_po() {
21+
# TGIs must be upper-case.
22+
ID="[0-9A-F]\{8\}"
23+
# Every line of a multi-line string should start and end with quotes.
24+
QUOTEDTEXT='".*"'
25+
sed -e "/^msgctxt\s\+\"$ID-$ID-$ID\"$/d" \
26+
-e "/^msgid\s\+$QUOTEDTEXT$/d" \
27+
-e "/^msgstr\s\+$QUOTEDTEXT$/d" \
28+
-e "/^msgstr\s\+$QUOTEDTEXT$/d" \
29+
-e "/^$QUOTEDTEXT$/d"
30+
}
31+
32+
echo "Checking .po file syntax..."
33+
34+
sorted_input_files | strip_comments_and_whitespace -0 | strip_valid_po > "$OUT"
35+
36+
if [ -s "$OUT" ]; then
37+
# the log file is not-empty
38+
echo "Syntax errors in .po files (use uppercase TGIs and quotes on every line of text):"
39+
cat "$OUT"
40+
rm -f "$OUT"
41+
exit 1
42+
else
43+
echo "No syntax errors found."
44+
rm -f "$OUT"
45+
exit 0
46+
fi

src/scripts/syntax-check-rul2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ strip_drive_side() {
2121
# newlines at the end of input files gracefully (unlike cat).
2222

2323
strip_comments_and_whitespace() {
24-
sed -e "s/;.*//" -e "s/\s\+//g" -e '/^\s*$/d'
24+
sed -e 's/;.*//' -e 's/\s\+//g' -e '/^\s*$/d'
2525
}
2626

2727
strip_valid_rul2() {

0 commit comments

Comments
 (0)