-
Notifications
You must be signed in to change notification settings - Fork 12
/
update-tool.sh
executable file
·156 lines (136 loc) · 4.17 KB
/
update-tool.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# Note: Do not call this script inside translations repo in read-only checkout!
# Make R/W checkout instead.
BRANCH=master
set -o errexit
# weblate_create yast_textdomain branch
function weblate_create() {
local YAST_PROJECT YAST_BRANCH
if test -n "$2" ; then
YAST_BRANCH=$2
else
YAST_BRANCH=master
fi
# Ugly hack! We want openSUSE for master.
case "$1/$YAST_BRANCH" in
control/master )
YAST_PROJECT=skelcd-control-openSUSE
;;
* )
YAST_PROJECT=$(sed -n "s/^$1 //p" <$WORKDIR/po/DOMAIN_MAP)
;;
esac
local WEBLATE_PROJECT=yast-$PROJECT
local PROJECT_NAME=yast-$1
local PROJECT_SLUG="$(echo $PROJECT_NAME | tr A-Z. a-z-)"
if test -n "$(echo $PROJECT_SLUG | sed 's/[-a-z0-9_]//g')" ; then
echo "Project URL slug \"$PROJECT_SLUG\" should contain only lowercase letters, \"-\" and \"_\"." >&2
echo "Please fix or add a name convertor." >&2
exit 1
fi
local BRANCH_NAME=$2
local BRANCH_SLUG="$(echo $BRANCH_NAME | tr A-Z. a-z-)"
if test -n "$(echo $BRANCH_SLUG | sed 's/[-a-z0-9_]//g')" ; then
echo "Component URL slug \"$SLUG\" should contain only lowercase letters, \"-\" and \"_\"." >&2
echo "Please fix or add a name convertor." >&2
exit 1
fi
if ! curl -f -I https://l10n.opensuse.org/projects/$PROJECT_SLUG/ >/dev/null 2>&1 ; then
weblate_create_project $1 $YAST_PROJECT
fi
if ! curl -f -I https://l10n.opensuse.org/projects/$PROJECT_SLUG/$BRANCH_SLUG/ >/dev/null 2>&1 ; then
weblate_create_component $1 $YAST_PROJECT $YAST_BRANCH
fi
}
if test -f "update-tool.sh" ; then
cd ..
fi
if ! test -f "tools/update-tool.sh" ; then
echo "Please call this script from yast-translations top directory."
exit 1
fi
. tools/weblate-functions.inc
WORKDIR=$PWD
YAST_CHECKOUT=
for DIR in ~ "$PWD"/.. ; do
if test -d $DIR/yast-checkout ; then
YAST_CHECKOUT=$DIR/yast-checkout
fi
done
if test -z "$YAST_CHECKOUT" ; then
echo "No yast-checkout find. Do you want to do the checkout now? (Y/n)"
read
if test "$REPLY" = n ; then
exit 1
fi
mkdir ../yast-checkout-temp
cd ../yast-checkout-temp
git clone https://github.com/yast/yast-meta
mkdir ~/yast-checkout
cd ~/yast-checkout
$OLDPWD/../yast-checkout-temp/yast-meta/y2m read-only ALL
YAST_CHECKOUT=$PWD
rm -rf $OLDPWD/../yast-checkout-temp
fi
TRANDIR=$WORKDIR/po
TRANPARTS=$WORKDIR/po-parts
Y2MAKEPOT=$YAST_CHECKOUT/devtools/build-tools/scripts/y2makepot
Y2M=$YAST_CHECKOUT/meta/y2m
cd $YAST_CHECKOUT
$Y2M read-only ALL
$Y2M pull
shopt -s nullglob
rm -rf $TRANPARTS
for DIR in * ; do
[ "$DIR" != 'translations' ] || continue
if grep -q "^$DIR\$" $TRANDIR/SKIP_PROJECTS; then
continue
fi
pushd $DIR >/dev/null
rm -f *.pot
$Y2MAKEPOT
for POT in *.pot ; do
DOMAIN=${POT%.pot}
if grep -q "^$DOMAIN\\.pot$" $TRANDIR/OBSOLETE_POT_FILES; then
continue
fi
mkdir -p $TRANPARTS/$DOMAIN
cp -a $POT $TRANPARTS/$DOMAIN/$DIR.pot
done
popd >/dev/null
done
cd $TRANPARTS
rm -f $TRANDIR/DOMAIN_MAP
for DOMAIN in * ; do
mkdir -p $TRANDIR/$DOMAIN
# This is an ugly hack: Use the newest file as source of header
msgcat --use-first $(ls -1 --sort=time $DOMAIN/*.pot) -o $TRANDIR/$DOMAIN/$DOMAIN.pot.new
# DOMAIN_MAP is used for source reference. Use the project with largest pot file.
echo $DOMAIN $(cd $DOMAIN ; ls -1 --sort=size *.pot | head -n1 | sed s/\\.pot\$// ) >>$TRANDIR/DOMAIN_MAP
weblate_create $DOMAIN $BRANCH
pushd $TRANDIR/$DOMAIN >/dev/null
# prevent re-committing when pot file uses different line format
if test -f $DOMAIN.pot ; then
msgcat $DOMAIN.pot -o $DOMAIN.pot.tmp
sed '1,11{/^"POT-Creation-Date:/d};1,12{/^"PO-Revision-Date:/d}' <$DOMAIN.pot.tmp >$DOMAIN.pot.nodate
sed '1,11{/^"POT-Creation-Date:/d};1,12{/^"PO-Revision-Date:/d}' <$DOMAIN.pot.new >$DOMAIN.pot.new.nodate
if cmp -s $DOMAIN.pot.nodate $DOMAIN.pot.new.nodate ; then
echo "No changes in $DOMAIN.pot. Skipping update."
rm *.tmp *.nodate *.new
popd >/dev/null
continue
fi
rm *.tmp *.nodate
fi
echo "Updating $DOMAIN."
mv $DOMAIN.pot.new $DOMAIN.pot
git add $DOMAIN.pot
for PO in *.po ; do
msgmerge --previous --lang=${PO%.po} $PO $DOMAIN.pot -o $PO.new
mv $PO.new $PO
git add $PO
done
git commit -m "Automatic update of $DOMAIN."
popd >/dev/null
done
echo "If everything went OK, call \"git push\"."