-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-translations
92 lines (85 loc) · 3.26 KB
/
update-translations
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
#!/bin/sh
# update-translations <OKAPI> <TENANT> <OKAPIUSERNAME> <OKAPIPASSWORD>
# Or set environment variables $OKAPI $TENANT $OKAPIUSERNAME $OKAPIPASSWORD and
# call update-translations without arguments.
set -e
: ${OKAPI:=$1}
: ${OKAPI:=http://localhost:8081}
: ${TENANT:=$2}
: ${TENANT:=diku}
: ${OKAPIUSERNAME:=$3}
: ${OKAPIUSERNAME:=diku_admin}
: ${OKAPIPASSWORD:=$4}
: ${OKAPIPASSWORD:=admin}
TOKEN=$( curl -sS -D - -H "X-Okapi-Tenant: $TENANT" -H "Content-type: application/json" \
-d "{\"tenant\":\"$TENANT\",\"username\":\"$OKAPIUSERNAME\",\"password\":\"$OKAPIPASSWORD\"}" \
"$OKAPI/authn/login" \
| grep -i "^x-okapi-token: " | tr -d "\n\r" )
echo "TOKEN=$TOKEN"
process ()
{
notranslation=0
unchanged=0
updated=0
while read line
do
if [ -z "$line" ]
then
continue
fi
id=$(echo "$line" | cut -f 1)
newname=$(echo "$line" | cut -f 3)
if [ "x$newname" = "x" ]
then
notranslation=$(( notranslation + 1 ))
continue
fi
json=$(curl --dump-header dump-header -sS -H "X-Okapi-Tenant: $TENANT" -H "$TOKEN" "$OKAPI$1/$id")
header=$(cat dump-header)
rm dump-header
if echo "$header" | head -1 | grep -q 404
then
echo "$OKAPI$1/$id not found on server"
norecord=$(( norecord + 1 ))
continue
fi
if echo "$header" | head -1 | grep -v -q 200
then
echo "$header"
echo "$json"
break
fi
oldname=$(echo "$json" | jq -r '.name')
if [ "$oldname" = "$newname" ]
then
unchanged=$(( unchanged + 1 ))
continue
fi
# The upload.json file is needed because curl for Windows incorrectly encodes
# UTF-8 characters like umlauts when using -d "$json"
echo "$json" | jq --arg newname "$newname" '.name=$newname' > upload.json
curl -sS -H "X-Okapi-Tenant: $TENANT" -H "$TOKEN" -H "Content-Type: application/json" \
-X PUT -d '@upload.json' "$OKAPI$1/$id"
# rm upload.json
updated=$(( updated + 1 ))
done
echo "$updated updated, $unchanged unchanged, $norecord without record, $notranslation without translation for $1"
}
process /alternative-title-types < alternative-title-types.tsv
process /contributor-types < contributor-types_codes.tsv
process /holdings-types < holdings-types.tsv
process /instance-formats < instance-formats.tsv
process /instance-note-types < instance-note-types.tsv
process /instance-types < instance-types.tsv
process /modes-of-issuance < modes-of-issuance.tsv
process /material-types < material-types.tsv
process /nature-of-content-terms < nature-of-content-terms.tsv
process /instance-statuses < instance-statuses.tsv
process /contributor-name-types < contributor-name-types.tsv
process /electronic-access-relationships < electronic-access-relationships.tsv
process /holdings-note-types < holdings-note-types.tsv
process /item-note-types < item-note-types.tsv
process /identifier-types < identifier-types.tsv
process /call-number-types < call-number-types.tsv
process /item-damaged-statuses < item-damaged-statuses.tsv
process /instance-relationship-types < instance-relationship-types.tsv