-
Notifications
You must be signed in to change notification settings - Fork 6
/
update-translations.sh
executable file
·290 lines (221 loc) · 7.62 KB
/
update-translations.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/sh
# Author: Boris Pek <[email protected]>
# License: GPLv2 or later
# Created: 2017-06-16
# Updated: 2021-02-01
# Version: N/A
set -e
export CUR_DIR="$(dirname $(realpath -s ${0}))"
export MAIN_DIR="$(realpath -s ${CUR_DIR}/..)"
PROGRAM_NAME="psi"
PSI_DIR="${MAIN_DIR}/psi"
PLUGINS_DIR="${MAIN_DIR}/plugins"
PSIMEDIA_DIR="${MAIN_DIR}/psimedia"
PSIPLUS_L10N_DIR="${MAIN_DIR}/psi-plus-l10n"
# master release-1.x
PSI_RELEASE_BRANCH="master"
cd "${CUR_DIR}"
case "${1}" in
"up")
# Pulling changes from GitHub repo.
git pull --all
;;
"cm")
# Creating correct git commit.
git commit -a -m 'Sync translations with Psi+ project.'
;;
"push")
# Pushing changes into GitHub repo.
git push
git push --tags
;;
"make")
# Making precompiled localization files.
rm -f translations.pro
echo "TRANSLATIONS = \\" >> translations.pro
echo translations/*.ts >> translations.pro
lrelease ./translations.pro
mkdir -p out
mv translations/*.qm out/
;;
"install")
# Installing precompiled localization files into ${DESTDIR}.
[ -z "${DESTDIR}" ] && DESTDIR="/usr"
mkdir -p "${DESTDIR}/share/psi-plus/translations/"
cp out/*.qm "${DESTDIR}/share/psi-plus/translations/"
;;
"tarball")
# Generating tarball with precompiled localization files.
CUR_TAG="$(git tag -l | sort -r -V | head -n1)"
rm -rf ${PROGRAM_NAME}-translations-*
mkdir ${PROGRAM_NAME}-translations-${CUR_TAG}
cp out/*.qm ${PROGRAM_NAME}-translations-${CUR_TAG}
tar -cJf ${PROGRAM_NAME}-translations-${CUR_TAG}.tar.xz \
${PROGRAM_NAME}-translations-${CUR_TAG}
echo "Tarball with precompiled translation files is ready"
[ ! -z "$(which realpath)" ] && \\
echo "$(realpath ${CUR_DIR}/${PROGRAM_NAME}-translations-${CUR_TAG}.tar.xz)"
;;
"tr")
# Pulling updates from Psi+ project.
# Test Internet connection:
host github.com > /dev/null
git status
if [ -d "${PSIPLUS_L10N_DIR}" ]; then
echo "Updating ${PSIPLUS_L10N_DIR}"
cd "${PSIPLUS_L10N_DIR}"
git pull --all --prune
echo;
else
echo "Creating ${PSIPLUS_L10N_DIR}"
cd "${MAIN_DIR}"
git clone https://github.com/psi-plus/psi-plus-l10n.git
echo;
fi
cp -a "${PSIPLUS_L10N_DIR}/translations"/*.ts "${CUR_DIR}/translations/"
cp -a "${PSIPLUS_L10N_DIR}/desktop-file"/*.desktop "${CUR_DIR}/desktop-file/"
cp -a "${PSIPLUS_L10N_DIR}/AUTHORS" "${CUR_DIR}/"
cp -a "${PSIPLUS_L10N_DIR}/COPYING" "${CUR_DIR}/"
# find "${CUR_DIR}/translations/" -type f -exec sed -i "s|Psi+|Psi|g" {} \;
find "${CUR_DIR}/desktop-file/" -type f -exec sed -i "s|Psi+|Psi|g" {} \;
find "${CUR_DIR}/desktop-file/" -type f -exec sed -i "s|Psi-plus|Psi|g" {} \;
find "${CUR_DIR}/desktop-file/" -type f -exec sed -i "s|psi-plus|psi|g" {} \;
cd "${CUR_DIR}"
git status
;;
"tr_up")
# Full update of localization files.
git status
if [ -d "${PSI_DIR}" ]; then
echo "Updating ${PSI_DIR}"
cd "${PSI_DIR}"
git checkout .
git checkout "${PSI_RELEASE_BRANCH}"
git pull --all --prune
git submodule init
git submodule update
echo;
else
echo "Creating ${PSI_DIR}"
cd "${MAIN_DIR}"
git clone https://github.com/psi-im/psi.git
cd "${PSI_DIR}"
git checkout "${PSI_RELEASE_BRANCH}"
git submodule init
git submodule update
echo;
fi
if [ -d "${PLUGINS_DIR}" ]; then
echo "Updating ${PLUGINS_DIR}"
cd "${PLUGINS_DIR}"
git pull --all --prune
echo;
else
echo "Creating ${PLUGINS_DIR}"
cd "${MAIN_DIR}"
git clone https://github.com/psi-im/plugins.git
echo;
fi
if [ -d "${PSIMEDIA_DIR}" ]; then
echo "Updating ${PSIMEDIA_DIR}"
cd "${PSIMEDIA_DIR}"
git pull --all --prune
echo;
else
echo "Creating ${PSIMEDIA_DIR}"
cd "${MAIN_DIR}"
git clone https://github.com/psi-im/psimedia.git
echo;
fi
# beginning of magical hack
cd "${CUR_DIR}"
rm -fr tmp
mkdir tmp
cd tmp/
mkdir src
mkdir src/plugins
mkdir psimedia
cp -a "${PLUGINS_DIR}"/* "src/plugins/"
cp -a "${PSIMEDIA_DIR}"/psiplugin "psimedia/"
cd "${PSI_DIR}/src"
python3 ../admin/update_options_ts.py ../options/default.xml > \
"${CUR_DIR}/tmp/option_translations.cpp"
# ending of magical hack
cd "${CUR_DIR}"
rm -r translations.pro
echo "HEADERS = \\" >> translations.pro
find "${PSI_DIR}/iris" "${PSI_DIR}/src" "${CUR_DIR}/tmp" -type f -name "*.h" | \
while read var; do echo " ${var} \\" >> translations.pro; done
echo "SOURCES = \\" >> translations.pro
find "${PSI_DIR}/iris" "${PSI_DIR}/src" "${CUR_DIR}/tmp" -type f -name "*.cpp" | \
while read var; do echo " ${var} \\" >> translations.pro; done
echo " ${CUR_DIR}/tmp/*.cpp" >> translations.pro
echo "FORMS = \\" >> translations.pro
find "${PSI_DIR}/iris" "${PSI_DIR}/src" "${CUR_DIR}/tmp" -type f -name "*.ui" | \
while read var; do echo " ${var} \\" >> translations.pro; done
echo " ${CUR_DIR}/tmp/*.ui" >> translations.pro
echo "TRANSLATIONS = \\" >> translations.pro
echo translations/*.ts >> translations.pro
lupdate -verbose ./translations.pro
cp "${PSI_DIR}"/linux/*.desktop "${CUR_DIR}/desktop-file/"
git status
;;
"tr_fu")
# Fast update of localization files.
git status
lupdate -verbose ./translations.pro
cp "${PSI_DIR}"/linux/*.desktop "${CUR_DIR}/desktop-file/"
git status
;;
"tr_cl")
# Cleaning update of localization files.
git status
lupdate -verbose -no-obsolete ./translations.pro
cp "${PSI_DIR}"/linux/*.desktop "${CUR_DIR}/desktop-file/"
git status
;;
"tr_sync")
# Syncing of Guthub repos.
"${0}" tr
"${0}" tr_up
if [ "$(git status | grep 'translations/' | wc -l)" -gt 0 ]; then
"${0}" cm
fi
echo ;
;;
"desktop_up")
# Update main .desktop file
GENERICNAME_FULL_DATA=$(grep -r "GenericName\[" "${CUR_DIR}/desktop-file/" | grep -v '/psi.desktop:' | grep -v '/psi_en.desktop:')
GENERICNAME_FILTERED_DATA=$(echo "${GENERICNAME_FULL_DATA}" | sed -ne 's|^.*/psi_.*.desktop:\(.*\)$|\1|p')
GENERICNAME_SORTED_DATA=$(echo "${GENERICNAME_FILTERED_DATA}" | sort -uV)
COMMENT_FULL_DATA=$(grep -r "Comment\[" "${CUR_DIR}/desktop-file/" | grep -v '/psi.desktop:' | grep -v '/psi_en.desktop:')
COMMENT_FILTERED_DATA=$(echo "${COMMENT_FULL_DATA}" | sed -ne 's|^.*/psi_.*.desktop:\(.*\)$|\1|p')
COMMENT_SORTED_DATA=$(echo "${COMMENT_FILTERED_DATA}" | sort -uV)
DESKTOP_FILE="${CUR_DIR}/desktop-file/psi.desktop"
grep -v "GenericName\[" "${DESKTOP_FILE}" > "${DESKTOP_FILE}.tmp"
mv -f "${DESKTOP_FILE}.tmp" "${DESKTOP_FILE}"
grep -v "Comment\[" "${DESKTOP_FILE}" > "${DESKTOP_FILE}.tmp"
mv -f "${DESKTOP_FILE}.tmp" "${DESKTOP_FILE}"
echo "${GENERICNAME_SORTED_DATA}" >> "${DESKTOP_FILE}"
echo "${COMMENT_SORTED_DATA}" >> "${DESKTOP_FILE}"
# Update .desktop file for English localization
cp -f "${CUR_DIR}/desktop-file/psi.desktop" \
"${CUR_DIR}/desktop-file/psi_en.desktop"
;;
*)
# Help.
echo "Usage:"
echo " up cm push make install tarball"
echo " tr tr_up tr_fu tr_cl tr_co tr_sync desktop_up"
echo ;
echo "Examples:"
echo " ./update-translations.sh tr"
echo " ./update-translations.sh tr_up"
echo " ./update-translations.sh cm"
echo " ./update-translations.sh push"
echo " or"
echo " ./update-translations.sh tr_sync"
echo " ./update-translations.sh push"
;;
esac
exit 0