tools/find_outdated_engine_translations.sh
author nemo
Wed, 07 Nov 2018 15:18:09 -0500
changeset 14170 8d9e3af8abce
parent 14168 e337e9920440
child 14178 ef14da7670f1
permissions -rwxr-xr-x
ignore whitespace/case by default to reduce false positives
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14170
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
     1
#!/usr/bin/env bash
14166
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
#
14170
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    14
shopt -s checkwinsize 
14166
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
14170
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    18
IGNORE_CASE_WHITESPACE=1;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    19
if ((${#@}==2))
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    20
then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    21
    IGNORE_CASE_WHITESPACE=$2;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    22
fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    23
14166
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
14170
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    28
    echo "No language specified.";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    29
    exit;
14166
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
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
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
    37
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
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
    39
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
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
    41
do
14170
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    42
    REV=$(echo $f | sed 's/:.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    43
    CODE=$(echo $f | sed 's/^[0-9]\+:\s\+//;s/=.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    44
    OTHER=$(grep -P "^\s*\d+:\s+${CODE}" $TEMP_LANG);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    45
    if (($?==0));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    46
    then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    47
        OTHER_REV=$(echo $OTHER | sed 's/:.*//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    48
        if (($REV>$OTHER_REV));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    49
        then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    50
            TEXT=$(echo $f | sed 's/^\s*[0-9]\+:\s*[0-9]\+:[0-9]\+=//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    51
            OLD_TEXT=$(hg grep --all -r "1:$OTHER_REV" "$CODE" en.txt | tail -n1 | sed 's/.*en.txt:[0-9]\+:[+-]:[0-9]\+:[0-9]\+=//;s/
//');
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    52
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    53
            COMPARE_TEXT=$TEXT;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    54
            COMPARE_OLD_TEXT=$OLD_TEXT;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    55
            if (($IGNORE_CASE_WHITESPACE==1));
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    56
            then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    57
                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: 14168
diff changeset
    58
                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: 14168
diff changeset
    59
            fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    60
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    61
            if [ "$COMPARE_TEXT" != "$COMPARE_OLD_TEXT" ];
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    62
            then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    63
                if [ -z $COLUMNS ];
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    64
                then
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    65
                    printf '━%.0s' $(seq 74);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    66
                    echo "";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    67
                else
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    68
                    printf '━%.0s' $(seq $COLUMNS);
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    69
                fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    70
                echo "$TEXT ← Current English";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    71
                echo "$OLD_TEXT ← English at time of translation";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    72
                echo "$(echo $OTHER | sed 's/^\s*[0-9]\+:\s*[0-9]\{2\}:[0-9]\{2\}=//') ← current translation";
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    73
            fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    74
        fi;
8d9e3af8abce ignore whitespace/case by default to reduce false positives
nemo
parents: 14168
diff changeset
    75
    fi;
14166
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    76
done
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    77
fe5bfe70c3c2 Add nemo's script to check for outdated engine translations with some adaptations
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    78
rm $TEMP_EN $TEMP_LANG