Merge pull request #1307 from keepassxreboot/feature/fix-qtbase-translations

Fix missing qtbase translations
This commit is contained in:
Janek Bevendorff 2017-12-24 14:56:42 +01:00 committed by GitHub
commit 0a9b250d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 58 deletions

View File

@ -40,6 +40,7 @@ RUN set -x \
qt${QT5_VERSION}base \ qt${QT5_VERSION}base \
qt${QT5_VERSION}tools \ qt${QT5_VERSION}tools \
qt${QT5_VERSION}x11extras \ qt${QT5_VERSION}x11extras \
qt${QT5_VERSION}translations \
zlib1g-dev \ zlib1g-dev \
libxi-dev \ libxi-dev \
libxtst-dev \ libxtst-dev \

View File

@ -678,7 +678,8 @@ build() {
"$DOCKER_IMAGE" \ "$DOCKER_IMAGE" \
bash -c "cd /keepassxc/out/build-release && \ bash -c "cd /keepassxc/out/build-release && \
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \ cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \
-DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\" /keepassxc/src && \ -DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\" \
-DKEEPASSXC_DIST_TYPE=AppImage /keepassxc/src && \
make $MAKE_OPTIONS && make DESTDIR=/keepassxc/out/bin-release install/strip && \ make $MAKE_OPTIONS && make DESTDIR=/keepassxc/out/bin-release install/strip && \
/keepassxc/src/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME"" /keepassxc/src/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME""

View File

@ -1,3 +1,4 @@
# Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2014 Felix Geyer <debfx@fobos.de> # Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -21,6 +22,16 @@ message(STATUS "${TRANSLATION_FILES}")
qt5_add_translation(QM_FILES ${TRANSLATION_FILES}) qt5_add_translation(QM_FILES ${TRANSLATION_FILES})
if(MINGW)
file(GLOB QTBASE_TRANSLATIONS ${Qt5_DIR}/../../../share/qt5/translations/qtbase_*.qm)
elseif(APPLE OR KEEPASSXC_DIST_APPIMAGE)
file(GLOB QTBASE_TRANSLATIONS
/usr/share/qt/translations/qtbase_*.qm
/usr/share/qt5/translations/qtbase_*.qm
${Qt5_DIR}/../../../translations/qtbase_*.qm)
endif()
set(QM_FILES ${QM_FILES} ${QTBASE_TRANSLATIONS})
install(FILES ${QM_FILES} DESTINATION ${DATA_INSTALL_DIR}/translations) install(FILES ${QM_FILES} DESTINATION ${DATA_INSTALL_DIR}/translations)
add_custom_target(translations DEPENDS ${QM_FILES}) add_custom_target(translations DEPENDS ${QM_FILES})
add_dependencies(${PROGNAME} translations) add_dependencies(${PROGNAME} translations)

View File

@ -43,8 +43,11 @@ parts:
- libykpers-1-dev - libykpers-1-dev
stage-packages: stage-packages:
- dbus - dbus
- qttranslations5-l10n # common translations
install: | install: |
sed -i 's|Icon=keepassxc|Icon=${SNAP}/usr/share/icons/hicolor/256x256/apps/keepassxc.png|g' $SNAPCRAFT_PART_INSTALL/usr/share/applications/org.keepassxc.KeePassXC.desktop sed -i 's|Icon=keepassxc|Icon=${SNAP}/usr/share/icons/hicolor/256x256/apps/keepassxc.png|g' $SNAPCRAFT_PART_INSTALL/usr/share/applications/org.keepassxc.KeePassXC.desktop
organize:
usr/share/qt5/translations/*.qm: usr/share/keepassxc/translations/
after: [desktop-qt5] after: [desktop-qt5]
# Redefine desktop-qt5 stage packages to work with Ubuntu 17.04 # Redefine desktop-qt5 stage packages to work with Ubuntu 17.04

View File

@ -1,5 +1,5 @@
# Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
# Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> # Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -352,7 +352,7 @@ if(MINGW)
include(DeployQt4) include(DeployQt4)
install_qt4_executable(${PROGNAME}.exe) install_qt4_executable(${PROGNAME}.exe)
add_custom_command(TARGET ${PROGNAME} POST_BUILD add_custom_command(TARGET ${PROGNAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${Qt5Core_DIR}/../../../share/qt5/plugins/platforms/qwindows$<$<CONFIG:Debug>:d>.dll COMMAND ${CMAKE_COMMAND} -E copy_if_different ${Qt5_DIR}/../../../share/qt5/plugins/platforms/qwindows$<$<CONFIG:Debug>:d>.dll
$<TARGET_FILE_DIR:${PROGNAME}>) $<TARGET_FILE_DIR:${PROGNAME}>)
install(FILES $<TARGET_FILE_DIR:${PROGNAME}>/qwindows$<$<CONFIG:Debug>:d>.dll DESTINATION "platforms") install(FILES $<TARGET_FILE_DIR:${PROGNAME}>/qwindows$<$<CONFIG:Debug>:d>.dll DESTINATION "platforms")
endif() endif()

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de> * Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -21,33 +22,45 @@
#include <QDir> #include <QDir>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QLocale> #include <QLocale>
#include <QRegExp>
#include <QTranslator> #include <QTranslator>
#include <QRegularExpression>
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/FilePath.h" #include "core/FilePath.h"
void Translator::installTranslator() /**
* Install all KeePassXC and Qt translators.
*/
void Translator::installTranslators()
{ {
QString language = config()->get("GUI/Language").toString(); QString language = config()->get("GUI/Language").toString();
if (language == "system" || language.isEmpty()) { if (language == "system" || language.isEmpty()) {
language = QLocale::system().name(); language = QLocale::system().name();
} }
if (!installTranslator(language)) { const QStringList paths = {
// English fallback still needs translations for plurals #ifdef QT_DEBUG
if (!installTranslator("en_plurals")) { QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR),
#endif
filePath()->dataPath("translations")
};
bool translationsLoaded = false;
for (const QString& path : paths) {
translationsLoaded |= installTranslator(language, path) || installTranslator("en_plurals", path);
installQtTranslator(language, path);
}
if (!translationsLoaded) {
// couldn't load configured language or fallback
qWarning("Couldn't load translations."); qWarning("Couldn't load translations.");
} }
}
installQtTranslator(language);
availableLanguages();
} }
QList<QPair<QString, QString> > Translator::availableLanguages() /**
* @return list of pairs of available language codes and names
*/
QList<QPair<QString, QString>> Translator::availableLanguages()
{ {
const QStringList paths = { const QStringList paths = {
#ifdef QT_DEBUG #ifdef QT_DEBUG
@ -59,12 +72,13 @@ QList<QPair<QString, QString> > Translator::availableLanguages()
QList<QPair<QString, QString> > languages; QList<QPair<QString, QString> > languages;
languages.append(QPair<QString, QString>("system", "System default")); languages.append(QPair<QString, QString>("system", "System default"));
QRegExp regExp("keepassx_([a-zA-Z_]+)\\.qm", Qt::CaseInsensitive, QRegExp::RegExp2); QRegularExpression regExp("^keepassx_([a-zA-Z_]+)\\.qm$", QRegularExpression::CaseInsensitiveOption);
for (const QString& path : paths) { for (const QString& path : paths) {
const QStringList fileList = QDir(path).entryList(); const QStringList fileList = QDir(path).entryList();
for (const QString& filename : fileList) { for (const QString& filename : fileList) {
if (regExp.exactMatch(filename)) { QRegularExpressionMatch match = regExp.match(filename);
QString langcode = regExp.cap(1); if (match.hasMatch()) {
QString langcode = match.captured(1);
if (langcode == "en_plurals") { if (langcode == "en_plurals") {
langcode = "en"; langcode = "en";
} }
@ -85,46 +99,37 @@ QList<QPair<QString, QString> > Translator::availableLanguages()
return languages; return languages;
} }
bool Translator::installTranslator(const QString& language) /**
{ * Install KeePassXC translator.
const QStringList paths = { *
#ifdef QT_DEBUG * @param language translator language
QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR), * @param path local search path
#endif * @return true on success
filePath()->dataPath("translations") */
};
for (const QString& path : paths) {
if (installTranslator(language, path)) {
return true;
}
}
return false;
}
bool Translator::installTranslator(const QString& language, const QString& path) bool Translator::installTranslator(const QString& language, const QString& path)
{ {
QTranslator* translator = new QTranslator(qApp); QScopedPointer<QTranslator> translator(new QTranslator(qApp));
if (translator->load(QString("keepassx_").append(language), path)) { if (translator->load(QString("keepassx_%1").arg(language), path)) {
QCoreApplication::installTranslator(translator); return QCoreApplication::installTranslator(translator.take());
return true;
} }
else {
delete translator;
return false; return false;
}
} }
bool Translator::installQtTranslator(const QString& language) /**
* Install Qt5 base translator from the specified local search path or the default system path
* if no qtbase_* translations were found at the local path.
*
* @param language translator language
* @param path local search path
* @return true on success
*/
bool Translator::installQtTranslator(const QString& language, const QString& path)
{ {
QTranslator* qtTranslator = new QTranslator(qApp); QScopedPointer<QTranslator> qtTranslator(new QTranslator(qApp));
if (qtTranslator->load(QString("%1/qtbase_%2").arg(QLibraryInfo::location(QLibraryInfo::TranslationsPath), language))) { if (qtTranslator->load(QString("qtbase_%1").arg(language), path)) {
QCoreApplication::installTranslator(qtTranslator); return QCoreApplication::installTranslator(qtTranslator.take());
return true; } else if (qtTranslator->load(QString("qtbase_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
return QCoreApplication::installTranslator(qtTranslator.take());
} }
else {
delete qtTranslator;
return false; return false;
}
} }

View File

@ -24,13 +24,12 @@
class Translator class Translator
{ {
public: public:
static void installTranslator(); static void installTranslators();
static QList<QPair<QString, QString> > availableLanguages(); static QList<QPair<QString, QString>> availableLanguages();
private: private:
static bool installTranslator(const QString& language);
static bool installTranslator(const QString& language, const QString& path); static bool installTranslator(const QString& language, const QString& path);
static bool installQtTranslator(const QString& language); static bool installQtTranslator(const QString& language, const QString& path);
}; };
#endif // KEEPASSX_TRANSLATOR_H #endif // KEEPASSX_TRANSLATOR_H

View File

@ -99,7 +99,7 @@ int main(int argc, char** argv)
Config::createConfigFromFile(parser.value(configOption)); Config::createConfigFromFile(parser.value(configOption));
} }
Translator::installTranslator(); Translator::installTranslators();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// Don't show menu icons on OSX // Don't show menu icons on OSX