Revert "Move translations to internal resource"

This reverts commit 82e1412bb2b4216eba8c81e509ecf79949a64aaf.
This commit is contained in:
Mark Watkins 2014-06-16 09:56:06 +10:00
parent 8e424d1bb8
commit a96cff0047
7 changed files with 48 additions and 46 deletions

View File

@ -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>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -218,8 +218,7 @@ FORMS += \
oximeterimport.ui oximeterimport.ui
RESOURCES += \ RESOURCES += \
Resources.qrc \ Resources.qrc
../Translations.qrc
OTHER_FILES += \ OTHER_FILES += \
docs/index.html \ docs/index.html \
@ -239,6 +238,33 @@ OTHER_FILES += \
docs/intro.html \ docs/intro.html \
docs/statistics.xml 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) bundlelibs = $$cat($$PWD/../Bundle3rdParty)
#QExtSerialPort will be replaced soon with Qt5's QSerialPort #QExtSerialPort will be replaced soon with Qt5's QSerialPort

View File

@ -22,7 +22,6 @@
#include <QSettings> #include <QSettings>
#include <QTranslator> #include <QTranslator>
#include <QListWidget> #include <QListWidget>
#include <QDirIterator>
#ifndef nullptr #ifndef nullptr
#define nullptr NULL #define nullptr NULL
@ -30,8 +29,6 @@
#include "translation.h" #include "translation.h"
extern QString GetAppRoot(); //returns app root path plus trailing path separator.
void initTranslations(QSettings & settings) { void initTranslations(QSettings & settings) {
// (Ordinary character sets will just use the name before the first '.' in the filename.) // (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; 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 language = settings.value("Settings/Language").toString();
QString langfile, langname; QString langfile, langname;
@ -58,47 +69,21 @@ void initTranslations(QSettings & settings) {
langNames[en]="English"; langNames[en]="English";
// Scan through available translations, and add them to the list // 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) { for (int i = 0; i < list.size(); ++i) {
QFileInfo fi = list.at(i); QFileInfo fi = list.at(i);
QString name = fi.fileName().section('.', 0, 0); QString name = fi.fileName().section('.', 0, 0);
QString code = fi.fileName().section('.', 1, 1); QString code = fi.fileName().section('.', 1, 1);
qDebug() << "Detected" << name << "Translation";
if (langNames.contains(code)) { if (langNames.contains(code)) {
name = langNames[code]; name = langNames[code];
} else { } else {
langNames[code]=name; langNames[code]=name;
} }
qDebug() << "Found custom" << name << "translation" << transdir + fi.fileName(); langFiles[code]=fi.fileName();
langFiles[code]=transdir + fi.fileName();
} }
if (language.isEmpty() || !langNames.contains(language)) { if (language.isEmpty() || !langNames.contains(language)) {
@ -134,7 +119,6 @@ void initTranslations(QSettings & settings) {
langlist.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); langlist.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
int row = 0; int row = 0;
for (QHash<QString, QString>::iterator it = langNames.begin(); it != langNames.end(); ++it) { 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 & code = it.key();
const QString & name = it.value(); const QString & name = it.value();
QListWidgetItem *item = new QListWidgetItem(name); QListWidgetItem *item = new QListWidgetItem(name);
@ -165,7 +149,7 @@ void initTranslations(QSettings & settings) {
qDebug() << "Loading " << langname << " Translation" << langfile << "from" << transdir; qDebug() << "Loading " << langname << " Translation" << langfile << "from" << transdir;
QTranslator * translator = new QTranslator(); 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 :("; qWarning() << "Could not load translation" << langfile << "reverting to english :(";
} }