-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcheck_localizable
executable file
·53 lines (45 loc) · 1.57 KB
/
check_localizable
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
#!/bin/sh
#
# SPDX-FileCopyrightText: 2024 SUSE LLC
#
# SPDX-License-Identifier: Apache-2.0
res=0
grep -r . --include '*.go' --exclude '*_test.go' --exclude-dir='vendor' -n \
-e 'fmt\.Errorf("[^"]\+"' \
-e 'errors.New("[^"]\+"' \
-e '\(Fatal\|Error\|Info\|Warn\)()\(\.Err(err)\)\?\.Msgf\?("' \
-e '\.Flags()\.\(String\|Int\|Bool\)\(Slice\)\?\(Var\)\?P\?([^)]\+, \+"[^"]\+")' \
-e '\(Short\|Long\|Title\): \+["`]' | while read -r line
do
file=$(echo "$line"i | cut -d: -f1)
line_number=$(echo "$line" | cut -d: -f2)
previous_line_number=$(expr "$line_number" - 1)
# Check if a previous line exists
if [ "$previous_line_number" -gt 0 ]; then
previous_line=$(sed -n "${previous_line_number}p" ${file})
# Check if the previous line contains the ignore comment
if ! echo "$previous_line" | grep -q "// *l10n-ignore"; then
echo "$line"
fi
else
echo "$line" # Print it as there is no previous line to ignore.
res=1
fi
done
if test $res -ne 0; then
echo -e "Fix the non localizable strings\n"
res=1
fi
grep -r . --include '*.go' --exclude '*_test.go' --exclude-dir='vendor' -n \
-e '\(Trace\|Debug\)()\(\.Err(err)\)\?\.Msgf\?(P\?N\?L("' \
if test $? -eq 0; then
echo -e "Trace and debug messages shouldn't be localizable\n"
res=1
fi
grep -r . --include '*.go' --exclude '*_test.go' --exclude-dir='vendor' -n \
-e '\(Short\|Long\): \+P\?N\?L(["`][a-z]'
if test $? -eq 0; then
echo -e "Short and Long messages shouldn't start with a lowercase letter\n"
res=1
fi
exit $res