Debian Codegraph @

git-tp-sync

raw
1 #!/bin/bash
2 #
3 # git-tp-sync - downloads the latest PO files from translationproject.org
4 # and commits changes to your GIT repository.
5 #
6 # Features:
7 # - commit per PO file (no more huge commits for all .po files)
8 # - the commit "Author:" field is set according to the Last-Translator
9 #
10 # Copyright (C) 2007-2016 Karel Zak <[email protected]>
11 #
12 # This file is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This file is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22
23 PROJECT="xdg-user-dirs"
24 if [ -n "$1" ]; then
25 while (( "$#" )); do
26 if [ -n "$1" ]; then
27 rsync -Lrtvz rsync://translationproject.org/tp/latest/$PROJECT/$1.po po
28 fi
29 shift
30 done
31 else
32 rsync -Lrtvz rsync://translationproject.org/tp/latest/$PROJECT/ po
33 fi
34
35 PO_NEW=$(git ls-files -o | gawk '/po\/[[:alpha:]_\-]*\.po$/ { sub("po/", ""); print $0; }' | sort)
36 PO_MOD=$(git ls-files -m | gawk '/po\/[[:alpha:]_\-]*\.po$/ { sub("po/", ""); print $0; }' | sort)
37
38 function add_to_linguas {
39 local LANG="$1"
40 local LINGUAS="$2"
41
42 echo ${LANG/.po/} >> $LINGUAS
43 sort -u $LINGUAS | sed '/^#/d' > $LINGUAS-new
44 sed -i '1s/^/# please keep this list sorted alphabetically\n/' $LINGUAS-new
45 mv $LINGUAS-new $LINGUAS
46 }
47
48 function get_author {
49 echo $(gawk 'BEGIN { FS=": " } /Last-Translator/ { sub("\\\\n\"", ""); print $2 }' "$1")
50 }
51
52 function do_commit {
53 local MSG="$1"
54 local POFILE="$2"
55 local LINGUAS="$3"
56 local AUTHOR=$(get_author "$POFILE")
57
58 git commit --author "$AUTHOR" -m "$MSG" "$POFILE" $LINGUAS
59 }
60
61 for f in $PO_MOD; do
62 do_commit "po: update $f (from translationproject.org)" "po/$f"
63 done
64
65 for f in $PO_NEW; do
66 git add "po/$f"
67 add_to_linguas "$f" "po/LINGUAS"
68 do_commit "po: add $f (from translationproject.org)" "po/$f" "po/LINGUAS"
69 done
70