~vrruiz/+junk/TranslationChecker

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
#!/bin/bash

## Execute: check-i18n-deb <locale> <device-password>
## Needs adb shell access to a device with Ubuntu Touch
## Reports are in the format:
##   - WARNING: <description>
##   - ERROR: <description>

LOCALE=$1
PASSWORD=$2
DEB_SOURCES_DIR=/tmp/deb-sources/

PACKAGE_LIST="ubuntu-system-settings"

if [ "${LOCALE}" == "" ] || [ "${PASSWORD}" == "" ]; then
    echo "./${0##*/} <locale> <device-password>"
    exit 1
fi

if [ -d "${DEBDIR}" ]; then
    rm -Rf "${DEBDIR}"
fi

# Password management
adb shell "echo -e '#\x21/bin/sh\necho $PASSWORD' >/tmp/askpass.sh"
adb shell chmod +x /tmp/askpass.sh

# Install package required for "apt-get source"
#adb shell "SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get -y update"
#adb shell "SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get -y install dpkg-dev"

# Create temp directory
adb shell mkdir "${DEB_SOURCES_DIR}"

# Download packages
for package in ${PACKAGE_LIST}
do
    echo ">> ${package}"
    adb shell "cd ${DEB_SOURCES_DIR} && apt-get source ${package}"
done

# Download sources
DEBS_TGZ=/tmp/deb-sources/deb-sources.tgz
adb shell "rm -f \"${DEBS_TGZ}\""
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"`
adb shell "tar cvzf \"${DEBS_TGZ}\" ${deb_dirs}"
adb pull ${DEBS_TGZ}

# Remove temp files on the device
adb shell rm -Rf "${DEBS_TGZ}"
adb shell rm -Rf "${DEB_SOURCES_DIR}"
adb shell rm -f /tmp/askpass.sh

# Unpack tar.gz
if [ -d ./tmp/ ]; then
    rm -Rf ./tmp/
fi
tar xvzf deb-sources.tgz

## Get the .mo and .qml files from the device in a tgz
LOCALE_TGZ_FILE=deb-sources-locale.tgz
LOCALE_TGZ=/tmp/${LOCALE_TGZ_FILE}
adb shell "find /usr/share/locale-langpack/ -name \"*\" | grep "/${LOCALE}/LC_MESSAGES" | grep \"\(.mo\)$\" | xargs tar cvzf \"${LOCALE_TGZ}\""
adb pull ${LOCALE_TGZ}
# Check whether the tgz was pulled
if [ ! -f ${LOCALE_TGZ_FILE} ]; then
  exit 1
fi
# Clean up
if [ -d ./usr ]; then
    rm -Rf ./usr
fi
# Uncompress the tgz
tar xvzf ${LOCALE_TGZ_FILE}

## Check the translations
home=`pwd`
cd ./tmp/deb-sources/
# List click packages
packages=`ls`

# Loop over packages
for package in ${packages}
do
    package_name=`echo ${package} | sed -e "s/\(.*\)-[0-9\.\+]*/\1/"`
    echo ">> ${package} ${package_name}"
    cd ${package}
    # Output .po file
    package_po=${package}.po
    # Loop over .qml files
    qml_files=`find . -name *.qml`
    if [ "${qml_files}" != "" ]; then
        # Extract strings from .qml files and store it in a .po file
        xgettext --c++ --qt --keyword=tr --keyword=tr:1,2 \
                 --keyword=N_ --keyword=ctr:1c,2 \
                 --from-code=utf-8 \
                 -o "${package_po}" ${qml_files}
        # TODO: Telegram has multiple mo files
        locale_mo=`find ${home}/usr/ -name $package_name.mo`
        locale_po=`find $PWD -name *.po | head -n 1`
        # Check translations if some strings were extracted
        if [ "${locale_po}" != "" ]; then
            ${home}/checkpomo.py -p "${locale_po}" -m "${locale_mo}"
        else
            echo "WARNING: ${package} doesn\'t contain any string"
        fi
    else
        echo "WARNING: ${package} doesn\'t have any QML files"
    fi
    cd -
done
cd ${home}