1#!/bin/bash -e 2# 3# package GUI application 4# 5 6function convert_qt_translations() 7{ 8# Combine the Qt translation files we use into local qt_??.qm files. 9# 10# It is recommended to combine Qts .qm files, this script does that for 11# linux and macos, windeployqt does this for windows. 12# https://doc.qt.io/qt-5/linguist-programmers.html#deploying-translations 13# 14# This script is created from the log of the windows build from windeployqt 15# with Qt 5.12.1. 16# From the log you can see which translation files are used which depends on 17# which Qt modules we use. 18# In our case these are qtbase_*.qm, qtdeclarative_*qm and qtserialport_*.qm. 19# 20# Note with Qt5 the Qt distributed qt_xx.qm files are metacatalogs, and just 21# copying or converting them won't copy the dependencies. 22 23 if [ "${machine}" = "Mac" ]; then 24 resourcedir="${APPDIR}/Contents/Resources" 25 26 # caution, mktemp here is macos specific version 27 resourceskel="$(mktemp -t gpsbabel_package_app)" 28 echo '<?xml version="1.0" encoding="UTF-8"?>' > "$resourceskel" 29 echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"' >> "$resourceskel" 30 echo '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> "$resourceskel" 31 echo '<plist version="1.0">' >> "$resourceskel" 32 echo '<dict>' >> "$resourceskel" 33 echo ' <key>LprojCompatibleVersion</key>' >> "$resourceskel" 34 echo ' <string>123</string>' >> "$resourceskel" 35 echo ' <key>LprojLocale</key>' >> "$resourceskel" 36 echo ' <string>LANGUAGE</string>' >> "$resourceskel" 37 echo ' <key>LprojRevisionLevel</key>' >> "$resourceskel" 38 echo ' <string>1</string>' >> "$resourceskel" 39 echo ' <key>LprojVersion</key>' >> "$resourceskel" 40 echo ' <string>123</string>' >> "$resourceskel" 41 echo '</dict>' >> "$resourceskel" 42 echo '</plist>' >> "$resourceskel" 43 fi 44 45 pushd "$(${QMAKE} -query QT_INSTALL_TRANSLATIONS)" > /dev/null 46 languages=($(echo qtbase_??.qm | sed 's/qtbase_\(..\).qm/\1/g')) 47 for language in "${languages[@]}" 48 do 49 inputs=() 50 inputs+=("qtbase_${language}.qm") 51 if [ -e "qtdeclarative_${language}.qm" ]; then inputs+=("qtdeclarative_${language}.qm"); fi 52 if [ -e "qtserialport_${language}.qm" ]; then inputs+=("qtserialport_${language}.qm"); fi 53 "${LCONVERT}" -o "${LANGDIR}/qt_${language}.qm" "${inputs[@]}" 54 55 if [ "${machine}" = "Mac" ]; then 56 # Create locversion.plist in the bundle to trigger translations for 57 # the application menu and system buttons. See description at 58 # https://doc.qt.io/qt-5/macos-issues.html#translating-the-application-menu-and-native-dialogs 59 mkdir -p "${resourcedir}/${language}.lproj" 60 sed "s/LANGUAGE/${language}/" "${resourceskel}" > "${resourcedir}/${language}.lproj/locversion.plist" 61 fi 62 done 63 popd > /dev/null 64 65 if [ "${machine}" = "Mac" ]; then 66 rm "${resourceskel}" 67 fi 68} 69 70QMAKE="${QMAKE:-qmake}" 71 72LUPDATE="$(${QMAKE} -query QT_INSTALL_BINS)/lupdate" 73LRELEASE="$(${QMAKE} -query QT_INSTALL_BINS)/lrelease" 74LCONVERT="$(${QMAKE} -query QT_INSTALL_BINS)/lconvert" 75MACDEPLOYQT="$(${QMAKE} -query QT_INSTALL_BINS)/macdeployqt" 76 77case "$(uname -s)" in 78 Linux*) machine=Linux;; 79 Darwin*) machine=Mac;; 80 *) echo "Unknown kernel name $(uname -s)." 1>&2; exit 1;; 81esac 82 83# update our translations and compile them. 84"${LUPDATE}" app.pro 85"${LRELEASE}" app.pro 86 87if [ "${machine}" = "Linux" ]; then 88 # need absolute paths for convert_qt_translations() 89 APPDIR="$(pwd)/GPSBabelFE" 90 LANGDIR="${APPDIR}/translations" 91else 92 APPBUNDLE=GPSBabelFE.app 93 # need absolute paths for convert_qt_translations() 94 APPDIR="$(pwd)/${APPBUNDLE}" 95 LANGDIR="${APPDIR}/Contents/MacOS/translations" 96fi 97 98rm -fr "${LANGDIR}" 99mkdir -p "${LANGDIR}" 100 101# copy our compiled translations. 102cp gpsbabelfe_??.qm "${LANGDIR}" 103cp coretool/gpsbabel_??.qm "${LANGDIR}" 104 105# bundle Qt .qm files, deploy them with our .qm files, 106# and, for macos, make & deploy locversion.plist files. 107(convert_qt_translations) 108 109if [ "${machine}" = "Linux" ]; then 110 cp objects/gpsbabelfe "${APPDIR}" 111 cp ../gpsbabel "${APPDIR}" 112 cp gmapbase.html "${APPDIR}" 113 cp COPYING.txt "${APPDIR}" 114else # Mac 115 cp ../gpsbabel "${APPDIR}/Contents/MacOS/gpsbabel" 116 cp gmapbase.html "${APPDIR}/Contents/MacOS" 117 cp COPYING.txt "${APPDIR}/Contents/MacOS" 118 rm -f GPSBabelFE.dmg 119 # macdeploytqt likes relative paths or else the dmg mount points get funky. 120 "${MACDEPLOYQT}" "${APPBUNDLE}" -executable="${APPBUNDLE}/Contents/MacOS/gpsbabel" -dmg -verbose=2 121fi 122