|
1 #!/bin/sh - |
|
2 # Script to check all engine locale files (XX.txt) |
|
3 |
|
4 # HOW TO USE: |
|
5 # - Run this script in the tools/ directory. |
|
6 # Result: All problems and missing translations in .txt files will be reported |
|
7 |
|
8 # SYNTAX: |
|
9 # |
|
10 # ./check_engine_locale_files.sh [file_to_check [show_untranslated]] |
|
11 # |
|
12 # Optional parameters: |
|
13 # |
|
14 # * file_to_check: Add this if you want to check a single file. Use the special value ALL to check all files. |
|
15 # * show_untranslated: Set to 0 if you want to hide the list of untranslated files, set to 1 otherwise |
|
16 |
|
17 SHOW_UNTRANSLATED_STRINGS=1; |
|
18 CHECKED_FILES=*.txt |
|
19 |
|
20 # Parse command line |
|
21 if [[ $# -gt 0 ]] |
|
22 then |
|
23 if [ $1 = ALL ] |
|
24 then |
|
25 CHECKED_FILES=*.txt |
|
26 else |
|
27 CHECKED_FILES=$1; |
|
28 fi |
|
29 fi |
|
30 if [[ $# -gt 1 ]] |
|
31 then |
|
32 if [[ $2 -eq 1 ]] |
|
33 then |
|
34 SHOW_UNTRANSLATED_STRINGS=1; |
|
35 elif [[ $2 -eq 0 ]] |
|
36 then |
|
37 SHOW_UNTRANSLATED_STRINGS=0; |
|
38 fi |
|
39 fi |
|
40 |
|
41 cd ../share/hedgewars/Data/Locale; |
|
42 |
|
43 # Temporary files |
|
44 TEMP_SYMBOLS_EN=$(mktemp); |
|
45 TEMP_SYMBOLS=$(mktemp); |
|
46 TEMP_COMPARE=$(mktemp); |
|
47 TEMP_COMPARE_2=$(mktemp); |
|
48 TEMP_CHECK=$(mktemp); |
|
49 TEMP_TEMP=$(mktemp); |
|
50 declare -a TEMP_PARAMS; |
|
51 for n in 0 1 2 3 4 5 6 7 8 9 |
|
52 do |
|
53 TEMP_PARAMS[$n]=$(mktemp); |
|
54 done |
|
55 |
|
56 # Collect list of string IDs |
|
57 echo -n "" > $TEMP_SYMBOLS_EN; |
|
58 grep -o "^[0-9][0-9]:[0-9][0-9]=" en.txt | cut -c1-5 | sort | uniq > $TEMP_SYMBOLS_EN; |
|
59 TOTAL_STRINGS=`wc -l < $TEMP_SYMBOLS_EN`; |
|
60 |
|
61 # Collect strings with placeholders (only in 01:XX) |
|
62 for n in 0 1 2 3 4 5 6 7 8 9 |
|
63 do |
|
64 grep -o "^01:[0-9][0-9]=.*%$n.*" en.txt | cut -c1-5 | sort | uniq > $TEMP_PARAMS[$n]; |
|
65 done |
|
66 |
|
67 # Iterate through selected language files |
|
68 for CHECKED_LANG_FILE in $CHECKED_FILES; |
|
69 # Skip files that don't contain engine strings |
|
70 do |
|
71 if [[ $CHECKED_LANG_FILE == campaigns_* ]] || [[ $CHECKED_LANG_FILE == missions_* ]] || [ $CHECKED_LANG_FILE == CMakeLists.txt ] |
|
72 then |
|
73 continue; |
|
74 fi |
|
75 if [ ! -e $CHECKED_LANG_FILE ] |
|
76 then |
|
77 echo "ERROR: $CHECKED_LANG_FILE not found!"; |
|
78 continue; |
|
79 fi |
|
80 if [ ! -r $CHECKED_LANG_FILE ] |
|
81 then |
|
82 echo "ERROR: No permission to read $CHECKED_LANG_FILE!"; |
|
83 continue; |
|
84 fi |
|
85 |
|
86 # Start the tests |
|
87 echo "== $CHECKED_LANG_FILE =="; |
|
88 MISSING_STRINGS=0; |
|
89 HAS_PROBLEMS=0; |
|
90 |
|
91 grep -o "^[^0-9;]" $CHECKED_LANG_FILE > $TEMP_CHECK |
|
92 if [ -s $TEMP_CHECK ] |
|
93 then |
|
94 echo "ERROR! Line(s) which does not start with a digit or semicolon found. Problematic line(s):"; |
|
95 echo "----------"; |
|
96 cat $TEMP_CHECK; |
|
97 echo "----------"; |
|
98 HAS_PROBLEMS=1; |
|
99 fi |
|
100 |
|
101 if [ $CHECKED_LANG_FILE != en.txt ] |
|
102 then |
|
103 grep -o "^[0-9][0-9]:[0-9][0-9]=" $CHECKED_LANG_FILE | cut -c1-5 | sort | uniq > $TEMP_SYMBOLS; |
|
104 |
|
105 # Find strings with missing placeholders |
|
106 > $TEMP_COMPARE; |
|
107 > $TEMP_COMPARE_2; |
|
108 for n in 0 1 2 3 4 5 6 7 8 9 |
|
109 do |
|
110 grep -o "^01:[0-9][0-9]=.*%$n.*" $CHECKED_LANG_FILE | cut -c1-5 | sort | uniq > $TEMP_CHECK; |
|
111 comm $TEMP_PARAMS[$n] $TEMP_CHECK -2 -3 >> $TEMP_COMPARE; |
|
112 comm $TEMP_PARAMS[$n] $TEMP_CHECK -1 -3 >> $TEMP_COMPARE_2; |
|
113 done |
|
114 cat $TEMP_COMPARE | cut -c1-5 | sort | uniq > $TEMP_TEMP; |
|
115 cat $TEMP_TEMP > $TEMP_COMPARE; |
|
116 comm $TEMP_COMPARE $TEMP_SYMBOLS -1 -2 > $TEMP_TEMP; |
|
117 if [ -s $TEMP_TEMP ] |
|
118 then |
|
119 echo "ERROR! Missing placeholders in these strings:"; |
|
120 cat $TEMP_TEMP; |
|
121 HAS_PROBLEMS=1; |
|
122 fi |
|
123 cat $TEMP_COMPARE_2 | cut -c1-5 | sort | uniq > $TEMP_TEMP; |
|
124 cat $TEMP_TEMP > $TEMP_COMPARE_2; |
|
125 comm $TEMP_COMPARE_2 $TEMP_SYMBOLS -1 -2 > $TEMP_TEMP; |
|
126 if [ -s $TEMP_TEMP ] |
|
127 then |
|
128 echo "ERROR! Invalid placeholders found in these strings:"; |
|
129 cat $TEMP_TEMP; |
|
130 HAS_PROBLEMS=1; |
|
131 fi |
|
132 |
|
133 # Find superficial strings |
|
134 comm $TEMP_SYMBOLS_EN $TEMP_SYMBOLS -1 -3 > $TEMP_COMPARE; |
|
135 if [ -s $TEMP_COMPARE ] |
|
136 then |
|
137 echo "WARNING! Superficial strings that do not exist in en.txt:"; |
|
138 cat $TEMP_COMPARE; |
|
139 HAS_PROBLEMS=1; |
|
140 fi |
|
141 |
|
142 # Find missing translations |
|
143 comm $TEMP_SYMBOLS_EN $TEMP_SYMBOLS -2 -3 > $TEMP_COMPARE; |
|
144 if [ -s $TEMP_COMPARE ] |
|
145 then |
|
146 if [ $SHOW_UNTRANSLATED_STRINGS -eq 1 ] |
|
147 then |
|
148 echo "Missing translations:"; |
|
149 cat $TEMP_COMPARE; |
|
150 fi |
|
151 MISSING_STRINGS=`wc -l < $TEMP_COMPARE`; |
|
152 fi |
|
153 |
|
154 # Print summary |
|
155 if [ $MISSING_STRINGS -ne 0 ] |
|
156 then |
|
157 echo "Missing translations TOTAL: $MISSING_STRINGS/$TOTAL_STRINGS"; |
|
158 else |
|
159 echo "All strings translated!"; |
|
160 fi |
|
161 if [ $HAS_PROBLEMS -eq 1 ] |
|
162 then |
|
163 echo "Problems have been found."; |
|
164 fi |
|
165 else |
|
166 if [ $HAS_PROBLEMS -eq 0 ] |
|
167 then |
|
168 echo "No problems."; |
|
169 fi |
|
170 fi; |
|
171 |
|
172 done; |
|
173 |
|
174 # Clean up files |
|
175 rm $TEMP_SYMBOLS $TEMP_SYMBOLS_EN $TEMP_COMPARE $TEMP_COMPARE_2 $TEMP_CHECK $TEMP_TEMP; |