diff --git a/Translations.qrc b/Translations.qrc deleted file mode 100644 index 3fd2c360..00000000 --- a/Translations.qrc +++ /dev/null @@ -1,8 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>Translations/Chinese.cn.qm</file> - <file>Translations/Deutsch.de.qm</file> - <file>Translations/Francais.fr.qm</file> - <file>Translations/Nederlands.nl.qm</file> - </qresource> -</RCC> diff --git a/Translations/Chinese.cn.qm b/Translations/Chinese.cn.qm deleted file mode 100644 index 1e8d4e77..00000000 Binary files a/Translations/Chinese.cn.qm and /dev/null differ diff --git a/Translations/Deutsch.de.qm b/Translations/Deutsch.de.qm deleted file mode 100644 index b33a20a5..00000000 Binary files a/Translations/Deutsch.de.qm and /dev/null differ diff --git a/Translations/Francais.fr.qm b/Translations/Francais.fr.qm deleted file mode 100644 index f90323cd..00000000 Binary files a/Translations/Francais.fr.qm and /dev/null differ diff --git a/Translations/Nederlands.nl.qm b/Translations/Nederlands.nl.qm deleted file mode 100644 index f43ab731..00000000 Binary files a/Translations/Nederlands.nl.qm and /dev/null differ diff --git a/sleepyhead/sleepyhead.pro b/sleepyhead/sleepyhead.pro index 3bef082f..b0ba508b 100644 --- a/sleepyhead/sleepyhead.pro +++ b/sleepyhead/sleepyhead.pro @@ -218,8 +218,7 @@ FORMS += \ oximeterimport.ui RESOURCES += \ - Resources.qrc \ - ../Translations.qrc + Resources.qrc OTHER_FILES += \ docs/index.html \ @@ -239,6 +238,33 @@ OTHER_FILES += \ docs/intro.html \ docs/statistics.xml +win32 { + CONFIG(debug, debug|release) { + DDIR = $$OUT_PWD/debug/Translations + } + CONFIG(release, debug|release) { + DDIR = $$OUT_PWD/release/Translations + } + DDIR ~= s,/,\\,g + + TRANS_FILES += $$PWD/../Translations/*.qm + TRANS_FILES_WIN = $${TRANS_FILES} + TRANS_FILES_WIN ~= s,/,\\,g + + system(mkdir $$quote($$DDIR)) + + for(FILE,TRANS_FILES_WIN){ + system(xcopy /y $$quote($$FILE) $$quote($$DDIR)) + } + +} + +mac { + TransFiles.files = $$files(../Translations/*.qm) + TransFiles.path = Contents/Resources/Translations + QMAKE_BUNDLE_DATA += TransFiles +} + bundlelibs = $$cat($$PWD/../Bundle3rdParty) #QExtSerialPort will be replaced soon with Qt5's QSerialPort diff --git a/sleepyhead/translation.cpp b/sleepyhead/translation.cpp index 518c9d78..0a27bd54 100644 --- a/sleepyhead/translation.cpp +++ b/sleepyhead/translation.cpp @@ -22,7 +22,6 @@ #include <QSettings> #include <QTranslator> #include <QListWidget> -#include <QDirIterator> #ifndef nullptr #define nullptr NULL @@ -30,8 +29,6 @@ #include "translation.h" -extern QString GetAppRoot(); //returns app root path plus trailing path separator. - void initTranslations(QSettings & settings) { // (Ordinary character sets will just use the name before the first '.' in the filename.) @@ -48,6 +45,20 @@ void initTranslations(QSettings & settings) { QHash<QString, QString> langFiles; +#ifdef Q_OS_MAC + QString transdir = QDir::cleanPath(QCoreApplication::applicationDirPath() + + "/../Resources/Translations/"); + +#else + const QString transdir = QCoreApplication::applicationDirPath() + "/Translations/"; +#endif + + QDir dir(transdir); + qDebug() << "Scanning \"" << transdir << "\" for translations"; + dir.setFilter(QDir::Files); + dir.setNameFilters(QStringList("*.qm")); + + QFileInfoList list = dir.entryInfoList(); QString language = settings.value("Settings/Language").toString(); QString langfile, langname; @@ -58,47 +69,21 @@ void initTranslations(QSettings & settings) { langNames[en]="English"; // Scan through available translations, and add them to the list - qDebug() << "Scanning resources for translations"; - QDirIterator it(":/Translations", QDirIterator::Subdirectories); - while (it.hasNext()) { - - QString path = it.next(); - QString filename = path.section("/",-1); - QString name = filename.section('.', 0, 0); - QString code = filename.section('.', 1, 1); - - qDebug() << "Found internal" << name << "Translation"; - - if (langNames.contains(code)) { - name = langNames[code]; - } else { - langNames[code]=name; - } - - langFiles[code]=path; - } - - - const QString transdir = GetAppRoot()+"/Translations/"; - QDir dir(transdir); - qDebug() << "Scanning" << transdir << "for custom/updated translations"; - dir.setFilter(QDir::Files); - dir.setNameFilters(QStringList("*.qm")); - - QFileInfoList list = dir.entryInfoList(); - for (int i = 0; i < list.size(); ++i) { QFileInfo fi = list.at(i); QString name = fi.fileName().section('.', 0, 0); QString code = fi.fileName().section('.', 1, 1); + + qDebug() << "Detected" << name << "Translation"; + if (langNames.contains(code)) { name = langNames[code]; } else { langNames[code]=name; } - qDebug() << "Found custom" << name << "translation" << transdir + fi.fileName(); - langFiles[code]=transdir + fi.fileName(); + langFiles[code]=fi.fileName(); + } if (language.isEmpty() || !langNames.contains(language)) { @@ -134,7 +119,6 @@ void initTranslations(QSettings & settings) { langlist.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); int row = 0; for (QHash<QString, QString>::iterator it = langNames.begin(); it != langNames.end(); ++it) { - if (!langFiles.contains(it.key())) continue; const QString & code = it.key(); const QString & name = it.value(); QListWidgetItem *item = new QListWidgetItem(name); @@ -165,7 +149,7 @@ void initTranslations(QSettings & settings) { qDebug() << "Loading " << langname << " Translation" << langfile << "from" << transdir; QTranslator * translator = new QTranslator(); - if (!langfile.isEmpty() && !translator->load(langfile, "")) { + if (!langfile.isEmpty() && !translator->load(langfile, transdir)) { qWarning() << "Could not load translation" << langfile << "reverting to english :("; }