4
by Víctor R. Ruiz
Click and archive translation checks |
1 |
#!/bin/bash
|
2 |
||
3 |
## Execute: check-i18n-deb <locale> <device-password>
|
|
4 |
## Needs adb shell access to a device with Ubuntu Touch
|
|
5 |
## Reports are in the format:
|
|
6 |
## - WARNING: <description>
|
|
7 |
## - ERROR: <description>
|
|
8 |
||
9 |
LOCALE=$1 |
|
10 |
PASSWORD=$2 |
|
11 |
DEB_SOURCES_DIR=/tmp/deb-sources/ |
|
12 |
||
13 |
PACKAGE_LIST="ubuntu-system-settings" |
|
14 |
||
15 |
if [ "${LOCALE}" == "" ] || [ "${PASSWORD}" == "" ]; then |
|
16 |
echo "./${0##*/} <locale> <device-password>" |
|
17 |
exit 1 |
|
18 |
fi
|
|
19 |
||
20 |
if [ -d "${DEBDIR}" ]; then |
|
21 |
rm -Rf "${DEBDIR}" |
|
22 |
fi
|
|
23 |
||
24 |
# Password management
|
|
25 |
adb shell "echo -e '#\x21/bin/sh\necho $PASSWORD' >/tmp/askpass.sh" |
|
26 |
adb shell chmod +x /tmp/askpass.sh |
|
27 |
||
28 |
# Install package required for "apt-get source"
|
|
29 |
#adb shell "SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get -y update"
|
|
30 |
#adb shell "SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get -y install dpkg-dev"
|
|
31 |
||
32 |
# Create temp directory
|
|
33 |
adb shell mkdir "${DEB_SOURCES_DIR}" |
|
34 |
||
35 |
# Download packages
|
|
36 |
for package in ${PACKAGE_LIST} |
|
37 |
do
|
|
38 |
echo ">> ${package}" |
|
39 |
adb shell "cd ${DEB_SOURCES_DIR} && apt-get source ${package}" |
|
40 |
done
|
|
41 |
||
42 |
# Download sources
|
|
43 |
DEBS_TGZ=/tmp/deb-sources/deb-sources.tgz |
|
44 |
adb shell "rm -f \"${DEBS_TGZ}\"" |
|
45 |
deb_dirs=`adb shell "find ${DEB_SOURCES_DIR} -maxdepth 1 -type d | grep -v \"^.$\"" | sed -e "s/\/tmp\/deb-sources\/\r//" | sed -e "s/\r/ /g"` |
|
46 |
adb shell "tar cvzf \"${DEBS_TGZ}\" ${deb_dirs}" |
|
47 |
adb pull ${DEBS_TGZ} |
|
48 |
||
49 |
# Remove temp files on the device
|
|
50 |
adb shell rm -Rf "${DEBS_TGZ}" |
|
51 |
adb shell rm -Rf "${DEB_SOURCES_DIR}" |
|
52 |
adb shell rm -f /tmp/askpass.sh |
|
53 |
||
54 |
# Unpack tar.gz
|
|
55 |
if [ -d ./tmp/ ]; then |
|
56 |
rm -Rf ./tmp/ |
|
57 |
fi
|
|
58 |
tar xvzf deb-sources.tgz |
|
59 |
||
60 |
## Get the .mo and .qml files from the device in a tgz
|
|
61 |
LOCALE_TGZ_FILE=deb-sources-locale.tgz |
|
62 |
LOCALE_TGZ=/tmp/${LOCALE_TGZ_FILE} |
|
63 |
adb shell "find /usr/share/locale-langpack/ -name \"*\" | grep "/${LOCALE}/LC_MESSAGES" | grep \"\(.mo\)$\" | xargs tar cvzf \"${LOCALE_TGZ}\"" |
|
64 |
adb pull ${LOCALE_TGZ} |
|
65 |
# Check whether the tgz was pulled
|
|
66 |
if [ ! -f ${LOCALE_TGZ_FILE} ]; then |
|
67 |
exit 1 |
|
68 |
fi
|
|
69 |
# Clean up
|
|
70 |
if [ -d ./usr ]; then |
|
71 |
rm -Rf ./usr |
|
72 |
fi
|
|
73 |
# Uncompress the tgz
|
|
74 |
tar xvzf ${LOCALE_TGZ_FILE} |
|
75 |
||
76 |
## Check the translations
|
|
77 |
home=`pwd` |
|
78 |
cd ./tmp/deb-sources/
|
|
79 |
# List click packages
|
|
80 |
packages=`ls` |
|
81 |
||
82 |
# Loop over packages
|
|
83 |
for package in ${packages} |
|
84 |
do
|
|
85 |
package_name=`echo ${package} | sed -e "s/\(.*\)-[0-9\.\+]*/\1/"` |
|
86 |
echo ">> ${package} ${package_name}" |
|
87 |
cd ${package} |
|
88 |
# Output .po file
|
|
89 |
package_po=${package}.po |
|
90 |
# Loop over .qml files
|
|
91 |
qml_files=`find . -name *.qml` |
|
92 |
if [ "${qml_files}" != "" ]; then |
|
93 |
# Extract strings from .qml files and store it in a .po file
|
|
94 |
xgettext --c++ --qt --keyword=tr --keyword=tr:1,2 \ |
|
95 |
--keyword=N_ --keyword=ctr:1c,2 \ |
|
96 |
--from-code=utf-8 \ |
|
97 |
-o "${package_po}" ${qml_files} |
|
98 |
# TODO: Telegram has multiple mo files
|
|
99 |
locale_mo=`find ${home}/usr/ -name $package_name.mo` |
|
100 |
locale_po=`find $PWD -name *.po | head -n 1` |
|
101 |
# Check translations if some strings were extracted
|
|
102 |
if [ "${locale_po}" != "" ]; then |
|
103 |
${home}/checkpomo.py -p "${locale_po}" -m "${locale_mo}" |
|
104 |
else
|
|
105 |
echo "WARNING: ${package} doesn\'t contain any string" |
|
106 |
fi
|
|
107 |
else
|
|
108 |
echo "WARNING: ${package} doesn\'t have any QML files" |
|
109 |
fi
|
|
110 |
cd -
|
|
111 |
done
|
|
112 |
cd ${home} |