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
|
#!/bin/bash
#
# git-tp-sync - downloads the latest PO files from translationproject.org
# and commits changes to your GIT repository.
#
# Features:
# - commit per PO file (no more huge commits for all .po files)
# - the commit "Author:" field is set according to the Last-Translator
#
# Copyright (C) 2007-2016 Karel Zak <kzak@redhat.com>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
PROJECT="xdg-user-dirs"
if [ -n "$1" ]; then
while (( "$#" )); do
if [ -n "$1" ]; then
rsync -Lrtvz rsync://translationproject.org/tp/latest/$PROJECT/$1.po po
fi
shift
done
else
rsync -Lrtvz rsync://translationproject.org/tp/latest/$PROJECT/ po
fi
PO_NEW=$(git ls-files -o | gawk '/po\/[[:alpha:]_\-]*\.po/ { sub("po/", ""); print $0; }' | sort)
PO_MOD=$(git ls-files -m | gawk '/po\/[[:alpha:]_\-]*\.po/ { sub("po/", ""); print $0; }' | sort)
function add_to_linguas {
local LANG="$1"
local LINGUAS="$2"
echo ${LANG/.po/} >> $LINGUAS
sort -u $LINGUAS | sed '/^#/d' > $LINGUAS-new
sed -i '1s/^/# please keep this list sorted alphabetically\n/' $LINGUAS-new
mv $LINGUAS-new $LINGUAS
}
function get_author {
echo $(gawk 'BEGIN { FS=": " } /Last-Translator/ { sub("\\\\n\"", ""); print $2 }' "$1")
}
function do_commit {
local MSG="$1"
local POFILE="$2"
local LINGUAS="$3"
local AUTHOR=$(get_author "$POFILE")
git commit --author "$AUTHOR" -m "$MSG" "$POFILE" $LINGUAS
}
for f in $PO_MOD; do
do_commit "po: update $f (from translationproject.org)" "po/$f"
done
for f in $PO_NEW; do
git add "po/$f"
add_to_linguas "$f" "po/LINGUAS"
do_commit "po: add $f (from translationproject.org)" "po/$f" "po/LINGUAS"
done
|