~registry/enlightenment/l10n-export-0.21

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
75
76
77
78
79
80
81
82
#!/bin/bash
#
# Create an archive for a language from the Bazaar repository of Launchpad
# with the same file system directories as in Git.
#
# You can change the path of the local Bazaar local branch:
#    ./language-archive.sh LANG DATE ~/dev/bzr-e21-l10n-export
# Or run with the default paths:
#    ./language-archive.sh LANG DATE
# Or run for the changes since yesterday with the default paths:
#    ./language-archive.sh LANG
# Or run for the changes since yesterday with the default paths for the current language:
#    ./language-archive.sh
#
# With
# - LANG a valid language code (eg.: eo, fr)
# - DATE the last exportation date (eg.: 2012-12-05) or 'ever' to add all translations
#
# 2016-07-20

BZR_LOCAL=$(pwd)
BZR_URL='lp:~e17-users/enlightenment/l10n-export-0.21'
PACKAGES=" \
enlightenment-0.21/core/enlightenment:enlightenment \
"

if [ $# -ge 1 ]; then
	LANG=$1;
fi
if [ $# -ge 2 ]; then
	DATE=$2;
else
	DATE=`date --date='1 day ago' +%Y-%m-%d`
fi
if [ $# -ge 3 ]; then
	BZR_LOCAL=$3;
fi

if [ ! -d $BZR_LOCAL ]; then
	echo "initial branch of $BZR_URL"
	bzr branch $BZR_URL $BZR_LOCAL
fi

echo "bzr update"
bzr update $BZR_LOCAL
ARCHIVE=$LANG-0.20.tar
cd $BZR_LOCAL
rm -f $ARCHIVE*

for PACKAGE in $PACKAGES; do
	PATHS=(${PACKAGE//:/ });
	FILEPATH="${PATHS[1]}/$LANG.po";
	DEST="${PATHS[0]}/po/$LANG.po";
	if [ ! -f $FILEPATH ]; then
		echo "!!!! $FILEPATH does not exist!";
		continue;
	fi
	if [ $DATE != 'ever' ]; then
		if [ `bzr log | grep $DATE | wc -l` -eq 0 ]; then continue; fi
		# ignore unmodified translations
		if [ `bzr diff -r$DATE $FILEPATH | grep '^+msgstr' -A1 | grep -v '^+msgstr ""' | grep -v '^+' | grep -v '^--' | grep -v '^$' | wc -l` -eq 0 ]; then
			continue;
		fi
	fi
	# Test validity
	msgfmt -c --statistics -o /dev/null $FILEPATH 2> /dev/null;
	if [ $? -ne 0 ]; then
		echo "!!!! $FILEPATH is invalid and not added to the archive!";
		msgfmt -c --statistics -o /dev/null $FILEPATH;
		continue;
	fi
	#
	echo "+ $DEST";
	tar --append -f $ARCHIVE $FILEPATH --transform "s:$FILEPATH:$DEST:g";
done
if [ -f $ARCHIVE ]; then
	bzip2 $ARCHIVE
	rm -f $ARCHIVE
	echo "$ARCHIVE.bz2 is created with modified translations since $DATE."
else
	echo "No translations found for $LANG since $DATE."
fi