make translation loading more accurate
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 27 Feb 2011 12:06:28 +0000 (12:06 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 27 Feb 2011 12:06:28 +0000 (12:06 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@737 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/main.cpp

index 155845e..d709f30 100644 (file)
@@ -17,6 +17,7 @@
 #include <QHostInfo>
 #include <QIcon>
 #include <QInputDialog>
+#include <QLibraryInfo>
 #include <QLocale>
 #include <QMenu>
 #include <QMessageBox>
@@ -182,6 +183,21 @@ void MApplication::setMyStyle()
        }
 }
 
+static inline void loadTranslation(QTranslator&trans,const QString&lang,const QString&prog)
+{
+       QStringList lpath;
+       lpath <<QApplication::applicationDirPath() <<QLibraryInfo::location(QLibraryInfo::TranslationsPath);
+       for(int i=0;i<lpath.size();i++){
+               bool ok=trans.load(prog+"_"+lang,lpath[i]);
+               QString msg=QString("...loading %1_%2 from %3 ...%4")
+                        .arg(prog).arg(lang)
+                        .arg(lpath[i])
+                        .arg(ok?"ok":"failed");
+               qDebug("%s",msg.toAscii().data());
+               if(ok)return;
+       }
+}
+
 int main(int argc,char**argv)
 {
        //create global app
@@ -209,12 +225,10 @@ int main(int argc,char**argv)
        QLocale::setDefault(QLocale(lang));
        qDebug("Loading language %s",lang.toAscii().data());
        QTranslator qttrans;
-       bool ok=qttrans.load("qt_"+lang,QApplication::applicationDirPath());
-       qDebug("...loading qt_%s ...%s",lang.toAscii().data(),ok?"ok":"failed");
+       loadTranslation(qttrans,lang,"qt");
        app.installTranslator(&qttrans);
        QTranslator mstrans;
-       ok=mstrans.load("smoke_"+lang,QApplication::applicationDirPath());
-       qDebug("...loading smoke_%s ...%s",lang.toAscii().data(),ok?"ok":"failed");
+       loadTranslation(mstrans,lang,"smoke");
        app.installTranslator(&mstrans);
        if(lang!="--"&&lang!="")
                QLocale::setDefault(lang);