-
Notifications
You must be signed in to change notification settings - Fork 4
95 lines (77 loc) · 3.52 KB
/
dataportal-translation-linting.yml
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
name: Check Missing Translations
on:
pull_request:
branches:
- devel
- main
paths:
- 'Portal/src/Datahub.Portal/**'
push:
branches:
- devel
- main
paths:
- 'Portal/src/Datahub.Portal/**'
workflow_dispatch:
jobs:
check-translations:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install jq (for JSON processing)
run: sudo apt-get install -y jq
- name: Check for missing translations
run: |
# Define the path to focus on (Portal/src/Datahub.Portal)
target_path="Portal/src/Datahub.Portal"
# Load the English and French JSON files into variables
english_json=$(cat "$target_path/i18n/localization.json" | jq -r '.')
french_json=$(cat "$target_path/i18n/localization.fr.json" | jq -r '.')
# Create an array to hold file paths with matching Localizer patterns
matching_files=()
# Define the regex pattern to match @Localizer[""] or Localizer[""]
pattern='@Localizer\["|Localizer\["'
# Find all .cs and .razor files and search for the Localizer pattern
while IFS= read -r file; do
# Extract the relative path (strip the target_path)
relative_file="${file#$target_path/}"
# Search for the regex pattern in the file
if grep -qP "$pattern" "$file"; then
echo "Pattern found in file: $relative_file"
matching_files+=("$file")
fi
done < <(find "$target_path" -type f \( -name "*.cs" -o -name "*.razor" \))
# Now, we will search for missing translations in the matched files
error_found=0 # Variable to track if an error is found
# Iterate over the files with Localizer patterns
for file in "${matching_files[@]}"; do
# Extract the relative path (strip the target_path)
relative_file="${file#$target_path/}"
echo "Checking translations in file: $relative_file"
# Extract Localizer keys from the file (line-delimited)
keys=$(grep -Po '(?<=Localizer\["|@Localizer\[").+?(?="\])' "$file" | sort | uniq)
# Process each key line by line
while IFS= read -r key; do
# Shorten the key to the first 5 words inline using awk
shortened_key=$(echo "$key" | awk '{if (NF>5) {for(i=1;i<=5;i++) printf $i " "; print "..."} else print $0}')
# Check if the key exists in the English JSON file
if ! echo "$english_json" | jq -e --arg key "$key" '.[$key]' > /dev/null; then
echo "Error: Missing English translation for key '$shortened_key' in file '$relative_file'"
error_found=1
fi
# Check if the key exists in the French JSON file
if ! echo "$french_json" | jq -e --arg key "$key" '.[$key]' > /dev/null; then
echo "Error: Missing French translation for key '$shortened_key' in file '$relative_file'"
error_found=1
fi
done <<< "$keys"
done
# If any error is found, exit with an error code; otherwise, exit cleanly
if [ "$error_found" -eq 1 ]; then
echo "Missing translations detected!"
exit 1
else
echo "All translations found!"
exit 0
fi