File indexing completed on 2024-10-06 12:12:53

0001 #!/bin/bash
0002 
0003 # A script to download Marble Qt translations from KDE's SVN,
0004 # transform them to binary .qm format while limiting the scope
0005 # of translations to driving instructions. The output is a set
0006 # of routing-instructions_$lang.qm files that can be used to
0007 # have the routing-instructions binary translate driving 
0008 # instructions according to the system's locale.
0009 #
0010 # SPDX-License-Identifier: LGPL-2.1-or-later
0011 #
0012 # SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0013 #
0014 
0015 set -e
0016 
0017 workdir="$(mktemp -d)"
0018 
0019 prefix="svn://anonsvn.kde.org/home/kde/trunk/l10n-kde4"
0020 # Translations are loaded from SVN trunk. Usually the stable branches/tags
0021 # have a better translation coverage. To get them, choose a recent stable tag
0022 #, e.g. 4.12.3, see http://websvn.kde.org/tags/KDE/, and uncomment the two lines
0023 # below:
0024 #TAG="4.12.3"
0025 #prefix="svn://anonsvn.kde.org/home/kde/tags/KDE/${TAG}/kde-l10n/"
0026 
0027 echo "Processing translations, please wait. This can take some time..."
0028 svn -q export "${prefix}/subdirs" "${workdir}/subdirs"
0029 untranslated=""
0030 for i in $(cat "${workdir}/subdirs")
0031 do
0032         test -e "${workdir}/marble_qt.po" && rm "${workdir}/marble_qt.po"
0033         if svn -q export "${prefix}/${i}/messages/kdeedu/marble_qt.po" "${workdir}/marble_qt.po" 2>/dev/null
0034         then
0035           # Limit translations to RoutingInstruction.cpp
0036           # Assumption: All translations needed for routing-instructions are contained in this file
0037           grep -A 4 "#: src/lib/marble/routing/instructions/RoutingInstruction.cpp:" "${workdir}/marble_qt.po" | sed 's/^--$//' > "${workdir}/marble_fi.po"
0038 
0039           # Convert the gettext format to Qt's ts format. Set the translation context to QObject
0040           # Assumption: All translated strings are invoked by QObject::tr (from a private class)
0041           # and not from a QObject derived class. Otherwise this needs to be adjusted
0042           lconvert "${workdir}/marble_fi.po" -o routing-instructions_${i}.ts
0043           sed -i -e 's@<context>@<context>\n    <name>QObject</name>@' -e '/<name><\/name>/d' routing-instructions_${i}.ts
0044 
0045           # Convert to binary .qm file format
0046           lconvert routing-instructions_${i}.ts -o routing-instructions_${i}.qm
0047 
0048           # Examine number of translations, debug output
0049           total="$(grep '</message>' routing-instructions_${i}.ts | wc -l)"
0050           missing="$(grep '<translation type="unfinished">' routing-instructions_${i}.ts | wc -l)"
0051           if [[ "${total}" == "${missing}" ]]
0052           then
0053             untranslated="${untranslated} ${i}"
0054             rm routing-instructions_${i}.qm
0055           else
0056             echo "$i: $((total-missing)) of ${total} driving instructions translated"
0057           fi
0058           rm routing-instructions_${i}.ts
0059         else
0060           untranslated="${untranslated} ${i}"
0061         fi
0062 done
0063 
0064 rm "${workdir}/marble_qt.po"
0065 rm "${workdir}/marble_fi.po"
0066 rm "${workdir}/subdirs"
0067 rmdir "${workdir}"
0068 echo -e "Languages not yet translated:\n${untranslated}" | fold -s