Bump minimum cmake
[megaglest-data.git] / others / appdata / estimate-the-translations.sh
blob78dd1a335711ac5006557e011b488701d26eab03
1 #!/bin/sh
2 # Use this script to estimate percent of advancement of translations.
4 # ----------------------------------------------------------------------------
5 # 2016 Written by filux <heross(@@)o2.pl>
6 # Copyright (c) 2016 under GNU GPL v3.0+
7 LANG=C
9 CURRENTDIR="$(dirname "$(readlink -f "$0")")"
10 cd "$CURRENTDIR"
11 Appdata_file="$CURRENTDIR/megaglest.appdata.xml"
13 Lang_map="$(awk -F '=' '/lang_map/ {print "=" $2}' "$CURRENTDIR/../../.tx/config" | sed 's/[,=] /\\n/g')"
14 Translations_list="$(find "$CURRENTDIR/../../data/lang" -maxdepth 1 -name "*.lng" -type f \
15 | awk -F '/' '{ print $NF }' | awk -F '.lng' '{ print $1 }' | sort)"
16 En_files="$(find "$CURRENTDIR/../../" -maxdepth 4 -name "*english.lng" -o -name "*_default.lng" -type f)"
17 En_strings=0
18 for En_file in $En_files; do
19 En_strings="$(($En_strings + $(grep -v '^[;#]\|^[\t ]*$' "$En_file" -c)))"
20 done
21 Languages=" <languages>"
22 for Translation in $Translations_list; do
23 if [ "$Translation" != "english" ]; then
24 Tr_abbreviation="$(echo "$Lang_map" | awk -F ':' '/'$Translation'$/ {print $1}')"
25 Tr_files="$(find "$CURRENTDIR/../../" -maxdepth 4 -name "*${Translation}.lng" -type f)"
26 Tr_strings=0
27 for Tr_file in $Tr_files; do
28 Tr_strings="$(($Tr_strings + $(grep -v '^[;#]\|^[\t ]*$' "$Tr_file" -c)))"
29 done
30 Tr_perc="$(((($Tr_strings * 100) + ($En_strings / 2)) / $En_strings))"
31 # ^ correct rounding
32 else
33 Tr_abbreviation="en"; Tr_files="$En_files"; Tr_strings="$En_strings"; Tr_perc=100
35 Languages="$Languages||| <lang percentage=\"$Tr_perc\">$Tr_abbreviation</lang>"
36 Translations="${Translations}$Translation - $Tr_perc%, "
37 done
38 echo "$Translations"
39 Languages="$Languages||| </languages>"
40 sed -z -i -e 's/\n/|||/g' "$Appdata_file"; sleep 0.25s
41 sed -i -e "s@[ \t]*<languages>.*</languages>@$Languages@" "$Appdata_file"; sleep 0.25s
42 sed -z -i -e 's/|||/\n/g' "$Appdata_file"