aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libLumina/LuminaSingleApplication.cpp2
-rw-r--r--libLumina/LuminaSingleApplication.h1
-rw-r--r--libLumina/LuminaUtils.cpp20
-rw-r--r--libLumina/LuminaUtils.h2
4 files changed, 18 insertions, 7 deletions
diff --git a/libLumina/LuminaSingleApplication.cpp b/libLumina/LuminaSingleApplication.cpp
index 2b3689d8..120e4881 100644
--- a/libLumina/LuminaSingleApplication.cpp
+++ b/libLumina/LuminaSingleApplication.cpp
@@ -14,7 +14,7 @@
LSingleApplication::LSingleApplication(int &argc, char **argv, QString appname) : QApplication(argc, argv){
//Load the proper translation systems
- LUtils::LoadTranslation(this, appname);
+ cTrans = LUtils::LoadTranslation(this, appname); //save the translator for later
//Initialize a couple convenience internal variables
cfile = QDir::tempPath()+"/.LSingleApp-%1-%2";
QString username = QString(getlogin());
diff --git a/libLumina/LuminaSingleApplication.h b/libLumina/LuminaSingleApplication.h
index 44f282cb..e5a1d67d 100644
--- a/libLumina/LuminaSingleApplication.h
+++ b/libLumina/LuminaSingleApplication.h
@@ -43,6 +43,7 @@ private:
QLockFile *lockfile;
QLocalServer *lserver;
QString cfile;
+ QTranslator *cTrans; //current translation
void PerformLockChecks();
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp
index f4f3544c..31c7a103 100644
--- a/libLumina/LuminaUtils.cpp
+++ b/libLumina/LuminaUtils.cpp
@@ -130,7 +130,7 @@ QStringList LUtils::imageExtensions(){
return imgExtensions;
}
-void LUtils::LoadTranslation(QApplication *app, QString appname, QString locale){
+ QTranslator* LUtils::LoadTranslation(QApplication *app, QString appname, QString locale, QTranslator *cTrans){
//Get the current localization
QString langEnc = "UTF-8"; //default value
QString langCode = locale; //provided locale
@@ -148,20 +148,30 @@ void LUtils::LoadTranslation(QApplication *app, QString appname, QString locale)
}
if(app !=0){
qDebug() << "Loading Locale:" << appname << langCode << langEnc;
+ //If an existing translator was provided, remove it first (will be replaced)
+ if(cTrans!=0){ app->removeTranslator(cTrans); }
//Setup the translator
- QTranslator *CurTranslator = new QTranslator();
+ cTrans = new QTranslator();
//Use the shortened locale code if specific code does not have a corresponding file
- if(!QFile::exists(LOS::LuminaShare()+"i18n/"+appname+"_" + langCode + ".qm") ){
+ if(!QFile::exists(LOS::LuminaShare()+"i18n/"+appname+"_" + langCode + ".qm") && langCode!="en_US" ){
langCode.truncate( langCode.indexOf("_") );
}
- CurTranslator->load( appname+QString("_") + langCode, LOS::LuminaShare()+"i18n/" );
- app->installTranslator( CurTranslator );
+ if( cTrans->load( appname+QString("_") + langCode, LOS::LuminaShare()+"i18n/" ) ){
+ app->installTranslator( cTrans );
+ }else{
+ //Translator could not be loaded for some reason
+ cTrans = 0;
+ if(langCode!="en_US"){
+ qWarning() << " - Could not load Locale:" << langCode;
+ }
+ }
}else{
//Only going to set the encoding since no application given
qDebug() << "Loading System Encoding:" << langEnc;
}
//Load current encoding for this locale
QTextCodec::setCodecForLocale( QTextCodec::codecForName(langEnc.toUtf8()) );
+ return cTrans;
}
QStringList LUtils::knownLocales(){
diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h
index ba161436..6dcb9d45 100644
--- a/libLumina/LuminaUtils.h
+++ b/libLumina/LuminaUtils.h
@@ -49,7 +49,7 @@ public:
static QStringList imageExtensions();
//Load a translation file for a Lumina Project
- static void LoadTranslation(QApplication *app, QString appname, QString locale = "");
+ static QTranslator* LoadTranslation(QApplication *app, QString appname, QString locale = "", QTranslator *cTrans = 0);
//Other localization shortcuts
static QStringList knownLocales(); //Note: This only lists locales known to Lumina (so the i18n files need to be installed)
static void setLocaleEnv(QString lang, QString msg="", QString time="", QString num="" ,QString money="",QString collate="", QString ctype="");
bgstack15