aboutsummaryrefslogtreecommitdiff
path: root/tools/get-translated-release-notes.sh
blob: e44fcebc6b4fb0fafa372104a844efd704d88777 (plain)
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
#!/bin/sh

LANG_FILE=tools/release-notes-language-codes.csv
TMPDIR=/tmp/release-notes
OUTFILE=$TMPDIR/release-notes.md

function fetch() {
	for line in $(cat $LANG_FILE) ; do
		code=$(echo $line|cut -d "," -f1|tr -d " ")
		local=$(echo $line|cut -d "," -f2|tr -d " ")
		echo updating $local - $code
		mkdir -p $TMPDIR
		curl -sSfL --globoff -o $TMPDIR/strings-$code.xml "http://translate.wordpress.org/projects/apps/android/release-notes/$code/default/export-translations?filters[status]=current&format=android" || (echo Error downloading $code)
	done
}

# Clean up strings by removing starting / trailing whitespaces, convert \n to new lines, etc.
function cleanup() {
	sed 's/\\n/|/g'  \
	| tr '|' '\n' \
	| sed  's/<[^>]*>//g' \
	| sed -e 's/\\'/'/g' \
	| sed 's/^[[:space:]]*//g' \
	| sed 's/[[:space:]]*$//g'
}

function extract_release_notes() {
	comment=$1
	footer=$2
	rm -f $OUTFILE
	for line in $(cat $LANG_FILE) ; do
		code=$(echo $line|cut -d "," -f1|tr -d " ")
		name=$(echo $line|cut -d "," -f3-|tr -d " ")
		echo \# $name >> $OUTFILE
		echo >> $OUTFILE
		grep \"$comment\" $TMPDIR/strings-$code.xml | cleanup >> $OUTFILE
		grep \"$footer\" $TMPDIR/strings-$code.xml | cleanup >> $OUTFILE
		echo >> $OUTFILE
	done
}

if [ x"$2" == x ]; then
	echo Usage: $0 RELEASE_NOTES_ID FOOTER_ID
	echo Example: $0 release_note_35 release_note_footer
	exit 1
fi

fetch
extract_release_notes $1 $2
echo Generated file:
echo $OUTFILE