forked from hal/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zanata.sh
executable file
·149 lines (135 loc) · 3.93 KB
/
zanata.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
#!/bin/bash
ROOT="$PWD"
SCRIPT=`basename $0`
ARGS=$#
COMMAND=$1
SUB_COMMAND=$2
function usage {
echo -e "Usage: $SCRIPT <help|clean|info|push|pull>\n"
echo -e "Zanata wrapper script to push and pull the translatable resources to and from Zanata.\n"
echo " help Shows this help"
echo " clean Removes all temporary files"
echo " info Displays details about the translatable resources such as"
echo " number of constants, messages and preview files."
echo " push <all|bundles|previews> Pushes the specified resources to Zanata."
echo " The resources are first copied to target/zanata/push"
echo " pull <all|bundles|previews> Pulls the specified resources from Zanata."
echo " The resources are pulled to target/zanata/pull"
exit 1
}
function clean {
rm -rf target/zanata
}
function info {
find resources/src/main/resources/org/jboss/hal/resources -name "Constants*.properties" | xargs wc -l
find resources/src/main/resources/org/jboss/hal/resources -name "Messages*.properties" | xargs wc -l
find resources/src/main/resources/org/jboss/hal/resources/previews -name "*.html" | xargs wc -l
}
function verifyPushPull {
if [[ ${ARGS} -ne 2 ]]
then
usage
fi
case ${SUB_COMMAND} in
"all")
;;
"bundles")
;;
"previews")
;;
*)
usage
;;
esac
}
function push {
if [[ "$SUB_COMMAND" == "all" ]]
then
pushBundles
pushPreviews
elif [[ "$SUB_COMMAND" == "bundles" ]]
then
pushBundles
elif [[ "$SUB_COMMAND" == "previews" ]]
then
pushPreviews
else
usage
fi
}
function pushBundles {
mkdir -p target/zanata/push/bundles
cp resources/src/main/zanata/bundles/zanata.xml target/zanata/push/bundles
cp resources/src/main/resources/org/jboss/hal/resources/Constants*.properties target/zanata/push/bundles
cp resources/src/main/resources/org/jboss/hal/resources/Messages*.properties target/zanata/push/bundles
cd target/zanata/push/bundles
zanata-cli push --batch-mode
cd "${ROOT}"
}
function pushPreviews {
mkdir -p target/zanata/push/previews
cp resources/src/main/zanata/previews/zanata.xml target/zanata/push/previews
cp -R resources/src/main/resources/org/jboss/hal/resources/previews/ target/zanata/push/previews
cd target/zanata/push/previews
zanata-cli push --batch-mode --push-type source --file-types "HTML[html]" --excludes "**/**_**.html"
cd "${ROOT}"
}
function pull {
if [[ "$SUB_COMMAND" == "all" ]]
then
pullBundles
pullPreviews
elif [[ "$SUB_COMMAND" == "bundles" ]]
then
pullBundles
elif [[ "$SUB_COMMAND" == "previews" ]]
then
pullPreviews
else
usage
fi
}
function pullBundles {
mkdir -p target/zanata/pull/bundles
cp resources/src/main/zanata/bundles/zanata.xml target/zanata/pull/bundles
cd target/zanata/pull/bundles
zanata-cli pull --batch-mode
cd "${ROOT}"
}
function pullPreviews {
mkdir -p target/zanata/pull/previews
cp resources/src/main/zanata/previews/zanata.xml target/zanata/pull/previews
cd target/zanata/pull/previews
zanata-cli pull --batch-mode
cd "${ROOT}"
}
# Verify Zanata client is available
command -v zanata-cli >/dev/null 2>&1 || { echo >&2 "Zanata client not found. Follow the instructions at https://docs.zanata.org/en/release/client/ to install the client."; exit 1; }
# Check
if [[ ${ARGS} -eq 0 ]]
then
usage
fi
# and parse arguments
case ${COMMAND} in
"help")
usage
;;
"clean")
clean
;;
"info")
info
;;
"push")
verifyPushPull
push
;;
"pull")
verifyPushPull
pull
;;
*)
usage
;;
esac