feat: i18n support again.

This commit is contained in:
Gary Wang 2020-01-05 14:30:33 +08:00
parent a6cfd1a714
commit 3a6a4cbc68
2 changed files with 11 additions and 2 deletions

View File

@ -121,6 +121,9 @@ if (WIN32)
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/translations")
else ()
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/pineapple-pictures/translations")
target_compile_definitions(${EXE_NAME}
PRIVATE QM_FILE_INSTALL_DIR=${QM_FILE_INSTALL_DIR}
)
endif ()
install (

View File

@ -1,6 +1,7 @@
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDir>
#include <QTranslator>
#include <QUrl>
@ -8,9 +9,14 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// since we did `CONFIG += lrelease embed_translations`...
QTranslator translator;
translator.load(QString("PineapplePictures_%1").arg(QLocale::system().name()), ":/i18n/");
QString qmDir;
#ifdef _WIN32
qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
#else
qmDir = QString(QM_FILE_INSTALL_DIR);
#endif
translator.load(QString("PineapplePictures_%1").arg(QLocale::system().name()), qmDir);
a.installTranslator(&translator);
// parse commandline arguments