diff options
author | Ken Moore <ken@pcbsd.org> | 2014-12-30 11:20:57 -0500 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2014-12-30 11:20:57 -0500 |
commit | 3cee91a627ecced62f7eefdc38850ea5499f761c (patch) | |
tree | 93f59249f318a34ad5d9789bac1d155596eb7ff5 /libLumina/LuminaUtils.cpp | |
parent | Commit some more XLib->XCB conversions (everything for the task manager), and... (diff) | |
download | lumina-3cee91a627ecced62f7eefdc38850ea5499f761c.tar.gz lumina-3cee91a627ecced62f7eefdc38850ea5499f761c.tar.bz2 lumina-3cee91a627ecced62f7eefdc38850ea5499f761c.zip |
Clean up how translations are loaded for all the Lumina utilities, and also apply the relative path fixes to all LSingleApplication's forwarded inputs.
Diffstat (limited to 'libLumina/LuminaUtils.cpp')
-rw-r--r-- | libLumina/LuminaUtils.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index ed08857f..83bf8c1c 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -5,11 +5,19 @@ // See the LICENSE file for full details //=========================================== #include "LuminaUtils.h" + #include <QString> #include <QFile> #include <QStringList> #include <QObject> +#include <QTextCodec> +#include <QDebug> + +#include <LuminaOS.h> +//============= +// LUtils Functions +//============= int LUtils::runCmd(QString cmd, QStringList args){ QProcess *proc = new QProcess; proc->setProcessChannelMode(QProcess::MergedChannels); @@ -95,4 +103,37 @@ QStringList LUtils::listSubDirectories(QString dir, bool recursive){ } } return out; -}
\ No newline at end of file +} + +void LUtils::LoadTranslation(QApplication *app, QString appname){ + //Get the current localization + QString langEnc = "UTF-8"; //default value + QString langCode = getenv("LANG"); + if(langCode.isEmpty()){ langCode = getenv("LC_ALL"); } + if(langCode.isEmpty()){ langCode = "en_US.UTF-8"; } //default to US english + //See if the encoding is included and strip it out as necessary + if(langCode.contains(".")){ + langEnc = langCode.section(".",-1); + langCode = langCode.section(".",0,0); + } + //Now verify the encoding for the locale + if(langCode =="C" || langCode=="POSIX" || langCode.isEmpty()){ + langEnc = "System"; //use the Qt system encoding + } + qDebug() << "Loading Locale:" << appname << langCode << langEnc; + + //Setup the translator + /*if(CurTranslator != 0){ + //A Translator already loaded: unload it before loading the new one + app->removeTranslator(CurTranslator); + }*/ + QTranslator *CurTranslator = 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") ){ + langCode.truncate( langCode.indexOf("_") ); + } + CurTranslator->load( appname+QString("_") + langCode, LOS::LuminaShare()+"i18n/" ); + app->installTranslator( CurTranslator ); + //Load current encoding for this locale + QTextCodec::setCodecForLocale( QTextCodec::codecForName(langEnc.toUtf8()) ); +} |