language_statistics.sh 1.72 KB
Newer Older
1
#!/bin/bash
2
3
# -*- mode: sh; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=4 sts=4 expandtab autoindent:
Tails developers's avatar
Tails developers committed
4

5
set -eu
6
set -o pipefail
Tails developers's avatar
Tails developers committed
7

8
LANGUAGES=${@:-de fr pt}
9
10
11
12
13

count_msgids () {
    cat | grep -E '^msgid\s+' | wc -l
}

14
15
16
17
18
19
20
21
count_original_words () {
    cat | grep ^msgid | sed 's/^msgid "//g;s/"$//g' | wc -w
}

count_translated_words () {
    cat | grep ^msgstr | sed 's/^msgstr "//g;s/"$//g' | wc -w
}

22
statistics () {
23
    PO_MESSAGES="$(mktemp -t XXXXXX.$lang.po)"
Tails developers's avatar
Tails developers committed
24
    msgcat --files-from=$PO_FILES --output=$PO_MESSAGES
25
    TOTAL=$(msgattrib --no-obsolete $PO_MESSAGES | count_msgids)
26
27
28
    TOTAL_WC=$(
        msgattrib --no-obsolete --no-wrap $PO_MESSAGES | count_original_words
    )
29
30
31
32
33
    FUZZY=$(msgattrib --only-fuzzy --no-obsolete $PO_MESSAGES | count_msgids)
    TRANSLATED=$(
        msgattrib --translated --no-fuzzy --no-obsolete $PO_MESSAGES \
            | count_msgids
    )
34
35
36
37
38
    TRANSLATED_WC=$(
        msgattrib --translated --no-fuzzy --no-obsolete --no-wrap $PO_MESSAGES \
	    | count_translated_words
    )
    echo "$lang: $(($TRANSLATED*100/$TOTAL))% strings translated, $(($FUZZY*100/$TOTAL))% strings fuzzy, $(($TRANSLATED_WC*100/$TOTAL_WC))% words translated"
Tails developers's avatar
Tails developers committed
39
    rm -f $PO_FILES $PO_MESSAGES
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
}

# all PO files
echo "All PO files"
echo "============"
echo ""

for lang in $LANGUAGES ; do
    PO_FILES="$(mktemp -t XXXXXX.$lang)"
    find -iname "*.$lang.po" > $PO_FILES
    find -path "*/locale/$lang/LC_MESSAGES/*.po" >> $PO_FILES
    statistics $PO_FILES
done

# core PO files
echo ""
echo "Core PO files"
echo "============="
echo ""

for lang in $LANGUAGES ; do
    PO_FILES="$(mktemp -t XXXXXX.$lang)"
    cat contribute/l10n_tricks/core_po_files.txt | sed "s/$/.$lang.po/g" > $PO_FILES
    statistics $PO_FILES
Tails developers's avatar
Tails developers committed
64
done