|
1 #!/usr/bin/env bash |
|
2 # |
|
3 # Tool which tries to find outdated translations in the engine strings (*.txt) using hg blame. |
|
4 # Note this is only a heuristic; the output might not be 100% accurate. |
|
5 # Strings which this tool lists MIGHT be outdated, so you might want to re-translate them, if needed. |
|
6 # Run this in the tools/ directory. |
|
7 # |
|
8 # SYNTAX: |
|
9 # |
|
10 # ./find_outdated_engine_translations.sh <LANGUAGE> |
|
11 # |
|
12 # <LANGUAGE>: Language code of the language to check |
|
13 # |
|
14 shopt -s checkwinsize |
|
15 |
|
16 cd ../share/hedgewars/Data/Locale |
|
17 |
|
18 IGNORE_CASE_WHITESPACE=1; |
|
19 if ((${#@}==2)) |
|
20 then |
|
21 IGNORE_CASE_WHITESPACE=$2; |
|
22 fi; |
|
23 |
|
24 BLAMELANG=$1; |
|
25 |
|
26 if [ -z $BLAMELANG ] |
|
27 then |
|
28 echo "No language specified."; |
|
29 exit; |
|
30 fi; |
|
31 BLAMELANGFILE="$BLAMELANG.txt"; |
|
32 |
|
33 TEMP_EN=$(mktemp); |
|
34 TEMP_LANG=$(mktemp); |
|
35 |
|
36 #hg fa en.txt | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_EN; |
|
37 hg blame en.txt | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_EN; |
|
38 |
|
39 #hg fa $BLAMELANGFILE | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_LANG; |
|
40 hg blame $BLAMELANGFILE | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_LANG; |
|
41 |
|
42 cat $TEMP_EN | while read f; |
|
43 do |
|
44 REV=$(echo $f | sed 's/:.*//'); |
|
45 CODE=$(echo $f | sed 's/^[0-9]\+:\s\+//;s/=.*//'); |
|
46 OTHER=$(grep -P "^\s*\d+:\s+${CODE}" $TEMP_LANG); |
|
47 if (($?==0)); |
|
48 then |
|
49 OTHER_REV=$(echo $OTHER | sed 's/:.*//'); |
|
50 if (($REV>$OTHER_REV)); |
|
51 then |
|
52 TEXT=$(echo $f | sed 's/^\s*[0-9]\+:\s*[0-9]\+:[0-9]\+=//'); |
|
53 # script runs ~20% faster than with blame but nonstandard |
|
54 # OLD_TEXT=$(hg fa -r "$OTHER_REV" en.txt | grep -P "^\s*\d+:\s+${CODE}=" | sed 's/^\s*[0-9]\+:\s*[0-9]\+:[0-9]\+=//;s/ |
|
55 //'); |
|
56 OLD_TEXT=$(hg blame -r "$OTHER_REV" en.txt | grep -P "^\s*\d+:\s+${CODE}=" | sed 's/^\s*[0-9]\+:\s*[0-9]\+:[0-9]\+=//;s/ |
|
57 //'); |
|
58 |
|
59 COMPARE_TEXT=$TEXT; |
|
60 COMPARE_OLD_TEXT=$OLD_TEXT; |
|
61 if (($IGNORE_CASE_WHITESPACE==1)); |
|
62 then |
|
63 COMPARE_TEXT=$(echo $TEXT | sed 's/\s*//g' | tr A-Z a-z); |
|
64 COMPARE_OLD_TEXT=$(echo $OLD_TEXT | sed 's/\s*//g' | tr A-Z a-z); |
|
65 fi; |
|
66 |
|
67 if [ "$COMPARE_TEXT" != "$COMPARE_OLD_TEXT" ]; |
|
68 then |
|
69 if [ -z $COLUMNS ]; |
|
70 then |
|
71 printf '━%.0s' $(seq 74); |
|
72 echo ""; |
|
73 else |
|
74 printf '━%.0s' $(seq $COLUMNS); |
|
75 fi; |
|
76 echo "${CODE}=$TEXT ← Current English"; |
|
77 echo "${CODE}=$OLD_TEXT ← English at time of translation"; |
|
78 echo "${CODE}=$(echo $OTHER | sed 's/^\s*[0-9]\+:\s*[0-9]\{2\}:[0-9]\{2\}=//') ← current translation"; |
|
79 fi; |
|
80 fi; |
|
81 fi; |
|
82 done |
|
83 |
|
84 rm $TEMP_EN $TEMP_LANG |