Fix Cppcheck warning
This commit is contained in:
parent
aeefaf7004
commit
4854f0034d
|
@ -103,42 +103,42 @@ bool TranslationHandler::setLanguage(const QString &code)
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
error = QObject::tr("Unknown language specified!");
|
error = QObject::tr("Unknown language specified!");
|
||||||
failure = true;
|
failure = true;
|
||||||
}
|
} else {
|
||||||
|
// Make sure there is a translator
|
||||||
|
if (!mTranslator && !failure)
|
||||||
|
mTranslator = new QTranslator(this);
|
||||||
|
|
||||||
// Make sure there is a translator
|
//Load the new language
|
||||||
if (!mTranslator && !failure)
|
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
mTranslator = new QTranslator(this);
|
|
||||||
|
|
||||||
//Load the new language
|
QSettings settings;
|
||||||
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
QString datadir = settings.value("DATADIR").toString();
|
||||||
|
if (datadir.isEmpty())
|
||||||
|
datadir = appPath;
|
||||||
|
|
||||||
QSettings settings;
|
QString translationFile;
|
||||||
QString datadir = settings.value("DATADIR").toString();
|
if (QFile::exists(datadir + "/lang/" + mTranslations[index].mFilename + ".qm"))
|
||||||
if (datadir.isEmpty())
|
translationFile = datadir + "/lang/" + mTranslations[index].mFilename + ".qm";
|
||||||
datadir = appPath;
|
|
||||||
|
|
||||||
QString translationFile;
|
else if (QFile::exists(datadir + "/" + mTranslations[index].mFilename + ".qm"))
|
||||||
if (QFile::exists(datadir + "/lang/" + mTranslations[index].mFilename + ".qm"))
|
translationFile = datadir + "/" + mTranslations[index].mFilename + ".qm";
|
||||||
translationFile = datadir + "/lang/" + mTranslations[index].mFilename + ".qm";
|
|
||||||
|
|
||||||
else if (QFile::exists(datadir + "/" + mTranslations[index].mFilename + ".qm"))
|
else
|
||||||
translationFile = datadir + "/" + mTranslations[index].mFilename + ".qm";
|
translationFile = appPath + "/" + mTranslations[index].mFilename + ".qm";
|
||||||
|
|
||||||
else
|
if (!mTranslator->load(translationFile) && !failure) {
|
||||||
translationFile = appPath + "/" + mTranslations[index].mFilename + ".qm";
|
//If it failed, lets check if the default file exists
|
||||||
|
if (!QFile::exists(translationFile)) {
|
||||||
|
error = QObject::tr("Language file %1 not found!");
|
||||||
|
error = error.arg(translationFile);
|
||||||
|
failure = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mTranslator->load(translationFile) && !failure) {
|
//If file exists, there's something wrong with it
|
||||||
//If it failed, lets check if the default file exists
|
error = QObject::tr("Failed to load translation for language %1 from file %2");
|
||||||
if (!QFile::exists(translationFile)) {
|
error = error.arg(mTranslations[index].mName);
|
||||||
error = QObject::tr("Language file %1 not found!");
|
|
||||||
error = error.arg(translationFile);
|
error = error.arg(translationFile);
|
||||||
failure = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If file exists, there's something wrong with it
|
|
||||||
error = QObject::tr("Failed to load translation for language %1 from file %2");
|
|
||||||
error = error.arg(mTranslations[index].mName);
|
|
||||||
error = error.arg(translationFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failure) {
|
if (failure) {
|
||||||
|
|
Loading…
Reference in New Issue