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+
9 CURRENTDIR
="$(dirname "$
(readlink
-f "$0")")"
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)"
18 for En_file
in $En_files; do
19 En_strings
="$(($En_strings + $(grep -v '^[;#]\|^[\t ]*$' "$En_file" -c)))"
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)"
27 for Tr_file
in $Tr_files; do
28 Tr_strings
="$(($Tr_strings + $(grep -v '^[;#]\|^[\t ]*$' "$Tr_file" -c)))"
30 Tr_perc
="$(((($Tr_strings * 100) + ($En_strings / 2)) / $En_strings))"
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%, "
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"