#!/bin/bash

count() {
    local dir="${DIR}/translations/source/$1"
    shift
    for po in $(find "${dir}" -path "${dir}/helpcontent2" -prune -o -name '*.po'); do
        msgattrib $* - < "${po}" 2>/dev/null
    done | grep '^msgid' | wc -l
}

stat() {
    local all=$(count $1)
    local fuzzy=$(count $1 --only-fuzzy)
    local obsolete=$(count $1 --only-obsolete)
    local untranslated=$(count $1 --untranslated)

    echo $[(all - fuzzy - obsolete - untranslated) * 100 / all]
}

if [[ $# -lt 1 ]]; then
    echo >&2 "usage: translation-status.sh <dir> <locale>*"
    exit 1
fi

DIR="$1"
if [[ $# -gt 2 ]]; then
    shift
    LOCALES="$@"
else
    LOCALES="$(ls "${DIR}/translations/source")"
fi

for locale in ${LOCALES}; do
    echo "${locale}: $(stat ${locale}) %"
done

# vim: set ts=4 sw=4 et:
