diff --git a/Translations.qrc b/Translations.qrc new file mode 100644 index 00000000..3fd2c360 --- /dev/null +++ b/Translations.qrc @@ -0,0 +1,8 @@ + + + Translations/Chinese.cn.qm + Translations/Deutsch.de.qm + Translations/Francais.fr.qm + Translations/Nederlands.nl.qm + + diff --git a/Translations/Chinese.cn.qm b/Translations/Chinese.cn.qm new file mode 100644 index 00000000..1e8d4e77 Binary files /dev/null and b/Translations/Chinese.cn.qm differ diff --git a/Translations/Deutsch.de.qm b/Translations/Deutsch.de.qm new file mode 100644 index 00000000..b33a20a5 Binary files /dev/null and b/Translations/Deutsch.de.qm differ diff --git a/Translations/Francais.fr.qm b/Translations/Francais.fr.qm new file mode 100644 index 00000000..f90323cd Binary files /dev/null and b/Translations/Francais.fr.qm differ diff --git a/Translations/Nederlands.nl.qm b/Translations/Nederlands.nl.qm new file mode 100644 index 00000000..f43ab731 Binary files /dev/null and b/Translations/Nederlands.nl.qm differ diff --git a/sleepyhead/sleepyhead.pro b/sleepyhead/sleepyhead.pro index b0ba508b..3bef082f 100644 --- a/sleepyhead/sleepyhead.pro +++ b/sleepyhead/sleepyhead.pro @@ -218,7 +218,8 @@ FORMS += \ oximeterimport.ui RESOURCES += \ - Resources.qrc + Resources.qrc \ + ../Translations.qrc OTHER_FILES += \ docs/index.html \ @@ -238,33 +239,6 @@ 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 0a27bd54..518c9d78 100644 --- a/sleepyhead/translation.cpp +++ b/sleepyhead/translation.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #ifndef nullptr #define nullptr NULL @@ -29,6 +30,8 @@ #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.) @@ -45,20 +48,6 @@ void initTranslations(QSettings & settings) { QHash 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; @@ -69,12 +58,16 @@ void initTranslations(QSettings & settings) { langNames[en]="English"; // Scan through available translations, and add them to the list - 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() << "Scanning resources for translations"; + QDirIterator it(":/Translations", QDirIterator::Subdirectories); + while (it.hasNext()) { - qDebug() << "Detected" << name << "Translation"; + 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]; @@ -82,8 +75,30 @@ void initTranslations(QSettings & settings) { langNames[code]=name; } - langFiles[code]=fi.fileName(); + 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); + if (langNames.contains(code)) { + name = langNames[code]; + } else { + langNames[code]=name; + } + + qDebug() << "Found custom" << name << "translation" << transdir + fi.fileName(); + langFiles[code]=transdir + fi.fileName(); } if (language.isEmpty() || !langNames.contains(language)) { @@ -119,6 +134,7 @@ void initTranslations(QSettings & settings) { langlist.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); int row = 0; for (QHash::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); @@ -149,7 +165,7 @@ void initTranslations(QSettings & settings) { qDebug() << "Loading " << langname << " Translation" << langfile << "from" << transdir; QTranslator * translator = new QTranslator(); - if (!langfile.isEmpty() && !translator->load(langfile, transdir)) { + if (!langfile.isEmpty() && !translator->load(langfile, "")) { qWarning() << "Could not load translation" << langfile << "reverting to english :("; }