File: percentages.sh

package info (click to toggle)
drawing 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 17,676 kB
  • sloc: python: 8,539; xml: 275; sh: 147; makefile: 13
file content (74 lines) | stat: -rwxr-xr-x 1,685 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

function absolute_values () {
	echo "| language | translated | approximative | untranslated |"
	echo "|----------|------------|---------------|--------------|"

	old_ifs=$IFS
	IFS=','

	cd po
	for i in *.po; do
		[ -f "$i" ] || break
		stats_str=$(msgfmt --statistics $i 2>&1 >/dev/null)
		read -r -a stats_arr <<< "$stats_str"

		correct=$(echo ${stats_arr[0]}| grep -Eo "[[:digit:]]*")
		fuzzy=$(echo ${stats_arr[1]}| grep -Eo "[[:digit:]]*")
		untranslated=$(echo ${stats_arr[2]}| grep -Eo "[[:digit:]]*")
		: ${correct:=0}
		: ${fuzzy:=0}
		: ${untranslated:=0}

		echo "| ${i%%\.*} | $correct | $fuzzy | $untranslated |"
	done
	cd ..

	IFS=$old_ifs
}

################################################################################

function relative_percentages () {
	echo "| language | completion percentage |"
	echo "|----------|-----------------------|"

	old_ifs=$IFS
	IFS=','

	cd po
	for i in *.po; do
		[ -f "$i" ] || break
		stats_str=$(msgfmt --statistics $i 2>&1 >/dev/null)
		read -r -a stats_arr <<< "$stats_str"

		correct=$(echo ${stats_arr[0]}| grep -Eo "[[:digit:]]*")
		fuzzy=$(echo ${stats_arr[1]}| grep -Eo "[[:digit:]]*")
		untranslated=$(echo ${stats_arr[2]}| grep -Eo "[[:digit:]]*")
		: ${correct:=0}
		: ${fuzzy:=0}
		: ${untranslated:=0}

		total=$(($correct + $fuzzy + $untranslated))
		percentage=$(($correct * 100 /$total))
		echo "| ${i%%\.*} | $percentage% |"
	done
	cd ..

	IFS=$old_ifs
}

################################################################################

if [ $# = 0 ]; then
	echo "Available methods:"
	declare -F
	echo ""
	echo "Running relative_percentages by default"
	relative_percentages
else
	$1 $2
fi

exit 0