diff --git a/plugins/advancedviewplugin/advancedviewplugin.cpp b/plugins/advancedviewplugin/advancedviewplugin.cpp index c1ad9ad..3b3f308 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.cpp +++ b/plugins/advancedviewplugin/advancedviewplugin.cpp @@ -1,6 +1,9 @@ #include "advancedviewplugin.h" #include +#include +#include +#include #include #include "mainwindow.h" @@ -12,6 +15,20 @@ AdvancedViewPlugin::AdvancedViewPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("advancedviewplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation advancedviewplugin"; + } + } + else + { + qWarning() << "could not load translation advancedviewplugin"; + } } void AdvancedViewPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/advancedviewplugin/advancedviewplugin.h b/plugins/advancedviewplugin/advancedviewplugin.h index 02bfc66..73a4052 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.h +++ b/plugins/advancedviewplugin/advancedviewplugin.h @@ -2,6 +2,7 @@ #define ADVANCEDVIEWPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -18,6 +19,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // ADVANCEDVIEWPLUGIN_H diff --git a/plugins/advancedviewplugin/advancedviewplugin.pro b/plugins/advancedviewplugin/advancedviewplugin.pro index 5d31425..3f522ca 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.pro +++ b/plugins/advancedviewplugin/advancedviewplugin.pro @@ -42,3 +42,8 @@ TRANSLATIONS += translations/advancedviewplugin_en.ts \ OTHER_FILES += advancedviewplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/advancedviewplugin_en.qm \ + $${OUT_PWD}/translations/advancedviewplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/copy_translations.pri b/plugins/copy_translations.pri new file mode 100644 index 0000000..966c686 --- /dev/null +++ b/plugins/copy_translations.pri @@ -0,0 +1,6 @@ +copy_compiled_translations.input = COMPILED_TRANSLATIONS +copy_compiled_translations.output = $${OUT_PWD}/../../bin/translations/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT} +copy_compiled_translations.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy_compiled_translations.CONFIG += no_link +QMAKE_EXTRA_COMPILERS += copy_compiled_translations +PRE_TARGETDEPS += compiler_copy_compiled_translations_make_all diff --git a/plugins/lunchmealplugin/lunchmealplugin.cpp b/plugins/lunchmealplugin/lunchmealplugin.cpp index 209428e..0379d21 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.cpp +++ b/plugins/lunchmealplugin/lunchmealplugin.cpp @@ -1,6 +1,9 @@ #include "lunchmealplugin.h" #include +#include +#include +#include #include #include "mainwindow.h" @@ -12,6 +15,20 @@ LunchMealPlugin::LunchMealPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("lunchmealplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation lunchmealplugin"; + } + } + else + { + qWarning() << "could not load translation lunchmealplugin"; + } } void LunchMealPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/lunchmealplugin/lunchmealplugin.h b/plugins/lunchmealplugin/lunchmealplugin.h index 3c8f524..f2a0f7c 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.h +++ b/plugins/lunchmealplugin/lunchmealplugin.h @@ -2,6 +2,7 @@ #define LUNCHMEALPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -18,6 +19,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // LUNCHMEALPLUGIN_H diff --git a/plugins/lunchmealplugin/lunchmealplugin.pro b/plugins/lunchmealplugin/lunchmealplugin.pro index 8115f97..c3debe5 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.pro +++ b/plugins/lunchmealplugin/lunchmealplugin.pro @@ -32,3 +32,8 @@ TRANSLATIONS += translations/lunchmealplugin_en.ts \ OTHER_FILES += lunchmealplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/lunchmealplugin_en.qm \ + $${OUT_PWD}/translations/lunchmealplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/presenceplugin/presenceplugin.cpp b/plugins/presenceplugin/presenceplugin.cpp index 790c36e..3e5e64d 100644 --- a/plugins/presenceplugin/presenceplugin.cpp +++ b/plugins/presenceplugin/presenceplugin.cpp @@ -1,6 +1,9 @@ #include "presenceplugin.h" #include +#include +#include +#include #include "presencewidget.h" @@ -8,6 +11,20 @@ PresencePlugin::PresencePlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("presenceplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation presenceplugin"; + } + } + else + { + qWarning() << "could not load translation presenceplugin"; + } } void PresencePlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/presenceplugin/presenceplugin.h b/plugins/presenceplugin/presenceplugin.h index acee4b7..2fc9f87 100644 --- a/plugins/presenceplugin/presenceplugin.h +++ b/plugins/presenceplugin/presenceplugin.h @@ -2,6 +2,7 @@ #define PRESENCEPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -18,6 +19,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // PRESENCEPLUGIN_H diff --git a/plugins/presenceplugin/presenceplugin.pro b/plugins/presenceplugin/presenceplugin.pro index 3eef5d3..e3e1d82 100644 --- a/plugins/presenceplugin/presenceplugin.pro +++ b/plugins/presenceplugin/presenceplugin.pro @@ -30,3 +30,8 @@ TRANSLATIONS += translations/presenceplugin_en.ts \ OTHER_FILES += presenceplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/presenceplugin_en.qm \ + $${OUT_PWD}/translations/presenceplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/reportsplugin/reportsplugin.cpp b/plugins/reportsplugin/reportsplugin.cpp index ea8d0fa..ce4dec0 100644 --- a/plugins/reportsplugin/reportsplugin.cpp +++ b/plugins/reportsplugin/reportsplugin.cpp @@ -1,6 +1,9 @@ #include "reportsplugin.h" #include +#include +#include +#include #include "reportswidget.h" @@ -8,6 +11,20 @@ ReportsPlugin::ReportsPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("reportsplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation reportsplugin"; + } + } + else + { + qWarning() << "could not load translation reportsplugin"; + } } void ReportsPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/reportsplugin/reportsplugin.h b/plugins/reportsplugin/reportsplugin.h index 782caa2..469ac83 100644 --- a/plugins/reportsplugin/reportsplugin.h +++ b/plugins/reportsplugin/reportsplugin.h @@ -2,6 +2,7 @@ #define REPORTSPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -18,6 +19,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // REPORTSPLUGIN_H diff --git a/plugins/reportsplugin/reportsplugin.pro b/plugins/reportsplugin/reportsplugin.pro index 19d8c78..e5fcadf 100644 --- a/plugins/reportsplugin/reportsplugin.pro +++ b/plugins/reportsplugin/reportsplugin.pro @@ -30,3 +30,8 @@ TRANSLATIONS += translations/reportsplugin_en.ts \ OTHER_FILES += reportsplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/reportsplugin_en.qm \ + $${OUT_PWD}/translations/reportsplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/updaterplugin/updaterplugin.cpp b/plugins/updaterplugin/updaterplugin.cpp index 13ad888..c38ace3 100644 --- a/plugins/updaterplugin/updaterplugin.cpp +++ b/plugins/updaterplugin/updaterplugin.cpp @@ -1,6 +1,9 @@ #include "updaterplugin.h" #include +#include +#include +#include #include "mainwindow.h" #include "zeiterfassungsettings.h" @@ -12,6 +15,20 @@ UpdaterPlugin::UpdaterPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("updaterplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation updaterplugin"; + } + } + else + { + qWarning() << "could not load translation updaterplugin"; + } } void UpdaterPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/updaterplugin/updaterplugin.h b/plugins/updaterplugin/updaterplugin.h index 6ebf16b..51311b2 100644 --- a/plugins/updaterplugin/updaterplugin.h +++ b/plugins/updaterplugin/updaterplugin.h @@ -2,6 +2,7 @@ #define UPDATERPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -18,6 +19,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // UPDATERPLUGIN_H diff --git a/plugins/updaterplugin/updaterplugin.pro b/plugins/updaterplugin/updaterplugin.pro index 1671d2a..0e6f1ce 100644 --- a/plugins/updaterplugin/updaterplugin.pro +++ b/plugins/updaterplugin/updaterplugin.pro @@ -30,3 +30,8 @@ TRANSLATIONS += translations/updaterplugin_en.ts \ OTHER_FILES += updaterplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/updaterplugin_en.qm \ + $${OUT_PWD}/translations/updaterplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/weatherplugin/weatherplugin.cpp b/plugins/weatherplugin/weatherplugin.cpp index 674d9fb..b308b11 100644 --- a/plugins/weatherplugin/weatherplugin.cpp +++ b/plugins/weatherplugin/weatherplugin.cpp @@ -1,6 +1,9 @@ #include "weatherplugin.h" #include +#include +#include +#include #include #include "mainwindow.h" @@ -11,6 +14,20 @@ WeatherPlugin::WeatherPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("weatherplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation weatherplugin"; + } + } + else + { + qWarning() << "could not load translation weatherplugin"; + } } void WeatherPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/weatherplugin/weatherplugin.h b/plugins/weatherplugin/weatherplugin.h index 11ba9b0..c4dc84f 100644 --- a/plugins/weatherplugin/weatherplugin.h +++ b/plugins/weatherplugin/weatherplugin.h @@ -2,6 +2,7 @@ #define WEATHERPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -16,6 +17,9 @@ public: // ZeiterfassungPlugin interface void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // WEATHERPLUGIN_H diff --git a/plugins/weatherplugin/weatherplugin.pro b/plugins/weatherplugin/weatherplugin.pro index 5391064..43118e3 100644 --- a/plugins/weatherplugin/weatherplugin.pro +++ b/plugins/weatherplugin/weatherplugin.pro @@ -30,3 +30,8 @@ TRANSLATIONS += translations/weatherplugin_en.ts \ OTHER_FILES += weatherplugin.json include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/weatherplugin_en.qm \ + $${OUT_PWD}/translations/weatherplugin_de.qm + +include(../copy_translations.pri) diff --git a/zeiterfassung/main.cpp b/zeiterfassung/main.cpp index 61d015d..6bff758 100755 --- a/zeiterfassung/main.cpp +++ b/zeiterfassung/main.cpp @@ -34,14 +34,11 @@ struct { QVector plugins; -bool loadAndInstallTranslator(QTranslator &translator, - const QLocale &locale, - const QString &filename, - const QString &prefix = QString(), - const QString &directory = QString(), - const QString &suffix = QString()) +bool loadAndInstallTranslator(QTranslator &translator, const QString &filename) { - if(!translator.load(locale, filename, prefix, directory, suffix)) + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(!translator.load(QLocale(), filename, QStringLiteral("_"), dir)) { qWarning() << "could not load translation" << filename; return false; @@ -79,13 +76,11 @@ bool loadTranslations(QSplashScreen &splashScreen, ZeiterfassungSettings &settin settings.setLanguage(dialog.language()); } - QLocale locale(settings.language(), QLocale::Austria); - QLocale::setDefault(locale); + QLocale::setDefault(QLocale(settings.language(), QLocale::Austria)); - auto translationsDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); - loadAndInstallTranslator(translators.qtTranslator, locale, QStringLiteral("qt"), QStringLiteral("_"), translationsDir); - loadAndInstallTranslator(translators.zeiterfassungTranslator, locale, QStringLiteral("zeiterfassung"), QStringLiteral("_"), translationsDir); - loadAndInstallTranslator(translators.zeiterfassunglibTranslator, locale, QStringLiteral("zeiterfassunglib"), QStringLiteral("_"), translationsDir); + loadAndInstallTranslator(translators.qtTranslator, QStringLiteral("qt")); + loadAndInstallTranslator(translators.zeiterfassungTranslator, QStringLiteral("zeiterfassung")); + loadAndInstallTranslator(translators.zeiterfassunglibTranslator, QStringLiteral("zeiterfassunglib")); return true; }