mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 19:20:45 +00:00
Move translations to internal resource
Custom translations to SleepyHeadData/Translations folder
This commit is contained in:
parent
ba51fcc8e3
commit
aaa617003d
8
Translations.qrc
Normal file
8
Translations.qrc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<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>
|
BIN
Translations/Chinese.cn.qm
Normal file
BIN
Translations/Chinese.cn.qm
Normal file
Binary file not shown.
BIN
Translations/Deutsch.de.qm
Normal file
BIN
Translations/Deutsch.de.qm
Normal file
Binary file not shown.
BIN
Translations/Francais.fr.qm
Normal file
BIN
Translations/Francais.fr.qm
Normal file
Binary file not shown.
BIN
Translations/Nederlands.nl.qm
Normal file
BIN
Translations/Nederlands.nl.qm
Normal file
Binary file not shown.
@ -218,7 +218,8 @@ FORMS += \
|
|||||||
oximeterimport.ui
|
oximeterimport.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
Resources.qrc
|
Resources.qrc \
|
||||||
|
../Translations.qrc
|
||||||
|
|
||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
docs/index.html \
|
docs/index.html \
|
||||||
@ -238,33 +239,6 @@ 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
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include <QDirIterator>
|
||||||
|
|
||||||
#ifndef nullptr
|
#ifndef nullptr
|
||||||
#define nullptr NULL
|
#define nullptr NULL
|
||||||
@ -29,6 +30,8 @@
|
|||||||
|
|
||||||
#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.)
|
||||||
@ -45,20 +48,6 @@ 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;
|
||||||
@ -69,12 +58,16 @@ 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
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
qDebug() << "Scanning resources for translations";
|
||||||
QFileInfo fi = list.at(i);
|
QDirIterator it(":/Translations", QDirIterator::Subdirectories);
|
||||||
QString name = fi.fileName().section('.', 0, 0);
|
while (it.hasNext()) {
|
||||||
QString code = fi.fileName().section('.', 1, 1);
|
|
||||||
|
|
||||||
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)) {
|
if (langNames.contains(code)) {
|
||||||
name = langNames[code];
|
name = langNames[code];
|
||||||
@ -82,8 +75,30 @@ void initTranslations(QSettings & settings) {
|
|||||||
langNames[code]=name;
|
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)) {
|
if (language.isEmpty() || !langNames.contains(language)) {
|
||||||
@ -119,6 +134,7 @@ 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);
|
||||||
@ -149,7 +165,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, transdir)) {
|
if (!langfile.isEmpty() && !translator->load(langfile, "")) {
|
||||||
qWarning() << "Could not load translation" << langfile << "reverting to english :(";
|
qWarning() << "Could not load translation" << langfile << "reverting to english :(";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user