[Bf-docboard] Script to find out, how much has been translated
Anton Felix Lorenzen
anfelor at web.de
Tue Dec 22 23:31:15 CET 2015
Hi all,
I have made a small bash script, that shows, how much has already been
translated (~1% for German). It works on Linux, maybe Mac OS X, but not
on Windows (unless you use cygwin) and is quite slow.
Maybe you'll find it useful anyway.
Sincerely,
Anton Felix Lorenzen
PS: @Libellul: If I find time in the next days, I may add a search for
fuzzy tags, which would show outdated translations.
Script:
#!/bin/bash
# Usage: Copy it into the LC_MESSAGES directory,
# make it executable (chmod +x),
# and run it with a double-click
# First terminal argument specifies the name of the output file.
# Author: Anton Felix Lorenzen
# Purpose: Show, how much of a translation is already done
# License: Apache 2
# Uses the Internal Field seperator to split lines, store it first
OldIFS=$IFS
# Finds the file to write the output to
function outFile {
out="generated-translations-list.txt"
if [ -n "$1" ]; then
out=$1
echo $1
fi
echo $out
}
# Overwrites a file
function overwrite {
echo "" > $1
}
# The file to write the result to
out=`outFile $1`
overwrite $out
# Write a string to $out
function say {
echo $1 >> $out
}
# Get a list of all the .po-files within a directory
function getFiles {
tree -f | grep "\.po" | sed -r "s/^[\│\ \ \─\├\└]+//"
}
# Reset Variables to defaults
function resetVars {
# At the start of each file are two fake lines
# for editor information, we don't count them
msgstrs=-1
eMsgstrs=0
allMsgstrs=$allMsgstrs-1
allEMsgstrs=$allEMsgstrs-1
}
function foundMsgstr {
msgstrs+=1
allMsgstrs+=1
}
function foundEMsgstr {
eMsgstrs+=1
allEMsgstrs+=1
}
function eMsgstrFalsePositive {
eMsgstrs=$eMsgstrs-1
allEMsgstr=$allEMsgstr-1
}
# Handle one line of input of one .po file
# Makes use of an $line variable, $1 didn't work:
#
https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters
lastLineWasEmptyMsgStr=false
function handleLine {
if grep -q "msgstr" <<<"$line"; then
foundMsgstr
if grep -q 'msgstr ""' <<<"$line"; then
# An empty or a long msgstr, see below
foundEMsgstr # We count it as empty
lastLineWasEmptyMsgStr=true
fi
elif egrep -q "^\"" <<<"$line"; then
# The last msgstr spanned more than one line,
# so we put it in the wrong categorys.
if [ $lastLineWasEmptyMsgStr = true ]; then
eMsgstrFalsePositive
lastLineWasEmptyMsgStr=false
fi
elif [ $lastLineWasEmptyMsgStr = true ]; then
lastLineWasEmptyMsgStr=false
fi
}
# Declare the variables as integers
declare -i allMsgstrs=0 msgstrs=0 eMsgstrs=0 allEMsgstrs=0
# split the list into lines
i=0
while IFS='' read -r line || [[ -n "$line" ]]; do
filearray[i]=$line
i=$i+1
done <<< `getFiles`
# For each file of the list
for filename in $filearray
do
resetVars
# Read every line in that file
while IFS='' read -r line || [[ -n "$line" ]]; do
handleLine
done < "$filename"
percent=`echo "scale=2; $eMsgstrs / $msgstrs" | bc`
say "[empty: $eMsgstrs, all: $msgstrs, percent empty: $percent% ]
$filename"
done
percent=`echo "scale=2; $allEMsgstrs / $allMsgstrs" | bc`
say "\n\nSummary: msgstrs: $allMsgstrs, empty msgstrs: $allEMsgstrs,
percent empty: $percent%"
# Restore the IFS
IFS=$OldIFS
More information about the Bf-docboard
mailing list