tools/find_outdated_engine_translations.sh
author alfadur
Thu, 29 Aug 2019 00:20:41 +0300
changeset 15383 701ad89a9f2a
parent 14174 fac275de34e5
permissions -rwxr-xr-x
avoid time multiplication when not skipping ticks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
     1
#!/usr/bin/env bash
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
#
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
# Tool which tries to find outdated translations in the engine strings (*.txt) using hg blame.
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
# Note this is only a heuristic; the output might not be 100% accurate.
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
# Strings which this tool lists MIGHT be outdated, so you might want to re-translate them, if needed.
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
# Run this in the tools/ directory.
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
#
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
# SYNTAX:
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
#
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
# ./find_outdated_engine_translations.sh <LANGUAGE>
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
#
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
# <LANGUAGE>: Language code of the language to check
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
#
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    14
shopt -s checkwinsize 
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
cd ../share/hedgewars/Data/Locale
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    18
IGNORE_CASE_WHITESPACE=1;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    19
if ((${#@}==2))
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    20
then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    21
    IGNORE_CASE_WHITESPACE=$2;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    22
fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    23
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
BLAMELANG=$1;
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
if [ -z $BLAMELANG ]
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
then
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    28
    echo "No language specified.";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    29
    exit;
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
fi;
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    31
BLAMELANGFILE="$BLAMELANG.txt";
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    32
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
TEMP_EN=$(mktemp);
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
TEMP_LANG=$(mktemp);
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
14174
fac275de34e5 Blame is about 30% faster than grep
nemo
parents: 14173
diff changeset
    36
#hg fa en.txt | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_EN;
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
hg blame en.txt | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_EN;
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
14174
fac275de34e5 Blame is about 30% faster than grep
nemo
parents: 14173
diff changeset
    39
#hg fa $BLAMELANGFILE | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_LANG;
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
hg blame $BLAMELANGFILE | grep -P "^\s*\d+:\s+0[013-6]:" > $TEMP_LANG;
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    42
cat $TEMP_EN | while read f;
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
do
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    44
    REV=$(echo $f | sed 's/:.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    45
    CODE=$(echo $f | sed 's/^[0-9]\+:\s\+//;s/=.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    46
    OTHER=$(grep -P "^\s*\d+:\s+${CODE}" $TEMP_LANG);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    47
    if (($?==0));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    48
    then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    49
        OTHER_REV=$(echo $OTHER | sed 's/:.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    50
        if (($REV>$OTHER_REV));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    51
        then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    52
            TEXT=$(echo $f | sed 's/^\s*[0-9]\+:\s*[0-9]\+:[0-9]\+=//');
14174
fac275de34e5 Blame is about 30% faster than grep
nemo
parents: 14173
diff changeset
    53
			# script runs ~20% faster than with blame but nonstandard
fac275de34e5 Blame is about 30% faster than grep
nemo
parents: 14173
diff changeset
    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/
//');
fac275de34e5 Blame is about 30% faster than grep
nemo
parents: 14173
diff changeset
    55
            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/
//');
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    56
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    57
            COMPARE_TEXT=$TEXT;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    58
            COMPARE_OLD_TEXT=$OLD_TEXT;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    59
            if (($IGNORE_CASE_WHITESPACE==1));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    60
            then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    61
                COMPARE_TEXT=$(echo $TEXT | sed 's/\s*//g' | tr A-Z a-z);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    62
                COMPARE_OLD_TEXT=$(echo $OLD_TEXT | sed 's/\s*//g' | tr A-Z a-z);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    63
            fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    64
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    65
            if [ "$COMPARE_TEXT" != "$COMPARE_OLD_TEXT" ];
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    66
            then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    67
                if [ -z $COLUMNS ];
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    68
                then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    69
                    printf '━%.0s' $(seq 74);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    70
                    echo "";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    71
                else
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    72
                    printf '━%.0s' $(seq $COLUMNS);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    73
                fi;
14173
ef14da7670f1 add the code too
nemo
parents: 14165
diff changeset
    74
                echo "${CODE}=$TEXT ← Current English";
ef14da7670f1 add the code too
nemo
parents: 14165
diff changeset
    75
                echo "${CODE}=$OLD_TEXT ← English at time of translation";
ef14da7670f1 add the code too
nemo
parents: 14165
diff changeset
    76
                echo "${CODE}=$(echo $OTHER | sed 's/^\s*[0-9]\+:\s*[0-9]\{2\}:[0-9]\{2\}=//') ← current translation";
14165
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    77
            fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    78
        fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14163
diff changeset
    79
    fi;
14161
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    80
done
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    81
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    82
rm $TEMP_EN $TEMP_LANG