Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / wiki / src / contribute / l10n_tricks / language_statistics.sh
blobd4d01cafe0407446e05e3dc73d3b0931ba4ef14a
1 #!/bin/bash
2 # -*- mode: sh; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
3 # vim: set filetype=sh sw=4 sts=4 expandtab autoindent:
5 set -eu
6 set -o pipefail
8 LANGUAGES=${@:-de fr pt}
10 count_msgids () {
11 cat | grep -E '^msgid\s+' | wc -l
14 count_original_words () {
15 cat | grep ^msgid | sed 's/^msgid "//g;s/"$//g' | wc -w
18 count_translated_words () {
19 cat | grep ^msgstr | sed 's/^msgstr "//g;s/"$//g' | wc -w
22 statistics () {
23 PO_MESSAGES="$(mktemp -t XXXXXX.$lang.po)"
24 msgcat --files-from=$PO_FILES --output=$PO_MESSAGES
25 TOTAL=$(msgattrib --no-obsolete $PO_MESSAGES | count_msgids)
26 TOTAL_WC=$(
27 msgattrib --no-obsolete --no-wrap $PO_MESSAGES | count_original_words
29 FUZZY=$(msgattrib --only-fuzzy --no-obsolete $PO_MESSAGES | count_msgids)
30 TRANSLATED=$(
31 msgattrib --translated --no-fuzzy --no-obsolete $PO_MESSAGES \
32 | count_msgids
34 TRANSLATED_WC=$(
35 msgattrib --translated --no-fuzzy --no-obsolete --no-wrap $PO_MESSAGES \
36 | count_translated_words
38 echo " - $lang: $(($TRANSLATED*100/$TOTAL))% ($TRANSLATED) strings translated, $(($FUZZY*100/$TOTAL))% strings fuzzy, $(($TRANSLATED_WC*100/$TOTAL_WC))% words translated"
39 rm -f $PO_FILES $PO_MESSAGES
42 # sanity checks
44 if pwd | grep -qs 'wiki/src$' ; then
45 WEBSITE_ROOT_DIR='.'
46 elif [ -d '.git' ] ; then
47 WEBSITE_ROOT_DIR='wiki/src'
48 else
49 echo >&2 "Error: $(basename $0) is meant to be run either from the wiki/src directory,"
50 echo >&2 " or from the root of the source tree"
51 exit 1
54 # all PO files
55 echo "All website PO files"
56 echo "===================="
57 echo ""
59 for lang in $LANGUAGES ; do
60 PO_FILES="$(mktemp -t XXXXXX.$lang)"
61 find "$WEBSITE_ROOT_DIR" -iname "*.$lang.po" > $PO_FILES
62 find "$WEBSITE_ROOT_DIR" -path "*/locale/$lang/LC_MESSAGES/*.po" >> $PO_FILES
63 statistics $PO_FILES
64 done
66 # core PO files
67 echo ""
68 echo "[[Core PO files|contribute/l10n_tricks/core_po_files.txt]]"
69 echo "=========================================================="
70 echo ""
72 for lang in $LANGUAGES ; do
73 PO_FILES="$(mktemp -t XXXXXX.$lang)"
74 cat "$WEBSITE_ROOT_DIR"/contribute/l10n_tricks/core_po_files.txt \
75 | sed "s/$/.$lang.po/g" \
76 | sed "s,^,$WEBSITE_ROOT_DIR/," \
77 > $PO_FILES
78 statistics $PO_FILES
79 done