Merge remote-tracking branch 'origin/claudio-dev' into develop

preferencesAboutTextFull
Claudio Valerio 12 years ago
commit a07b09ec7a
  1. 102
      src/core/UBApplication.cpp
  2. 4
      src/core/UBApplication.h

@ -139,15 +139,7 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing
UBSettings *settings = UBSettings::settings(); UBSettings *settings = UBSettings::settings();
QString forcedLanguage(""); setupTranslators(args);
if(args.contains("-lang"))
forcedLanguage=args.at(args.indexOf("-lang") + 1);
else{
QString setLanguage = settings->appPreferredLanguage->get().toString();
if(!setLanguage.isEmpty())
forcedLanguage = setLanguage;
}
setupTranslator(forcedLanguage);
connect(settings->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(toolBarPositionChanged(QVariant))); connect(settings->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(toolBarPositionChanged(QVariant)));
connect(settings->appToolBarDisplayText, SIGNAL(changed(QVariant)), this, SLOT(toolBarDisplayTextChanged(QVariant))); connect(settings->appToolBarDisplayText, SIGNAL(changed(QVariant)), this, SLOT(toolBarDisplayTextChanged(QVariant)));
@ -207,45 +199,71 @@ UBApplication::~UBApplication()
staticMemoryCleaner = 0; staticMemoryCleaner = 0;
} }
void UBApplication::setupTranslator(QString forcedLanguage) QString UBApplication::checkLanguageAvailabilityForSankore(QString &language)
{
QStringList availableTranslations = UBPlatformUtils::availableTranslations();
if(availableTranslations.contains(language,Qt::CaseInsensitive))
return language;
else{
if(language.length() > 2){
QString shortLanguageCode = language.left(2);
if(availableTranslations.contains(shortLanguageCode,Qt::CaseInsensitive))
return shortLanguageCode;
}
}
return QString("");
}
void UBApplication::setupTranslators(QStringList args)
{ {
QStringList availablesTranslations = UBPlatformUtils::availableTranslations(); QString forcedLanguage;
QString language(""); if(args.contains("-lang"))
if(!forcedLanguage.isEmpty()){ forcedLanguage=args.at(args.indexOf("-lang") + 1);
if(availablesTranslations.contains(forcedLanguage,Qt::CaseInsensitive)) else{
language = forcedLanguage; QString setLanguage = UBSettings::settings()->appPreferredLanguage->get().toString();
else if(!setLanguage.isEmpty())
qDebug() << "forced language " << forcedLanguage << " not available"; forcedLanguage = setLanguage;
} }
else{
QString systemLanguage = UBPlatformUtils::systemLanguage(); QStringList availablesTranslations = UBPlatformUtils::availableTranslations();
if(availablesTranslations.contains(systemLanguage,Qt::CaseInsensitive)) QString language("");
language = systemLanguage;
else if(!forcedLanguage.isEmpty())
qDebug() << "translation for system language " << systemLanguage << " not found"; language = checkLanguageAvailabilityForSankore(forcedLanguage);
}
if(language.isEmpty()){
if(language.isEmpty()){ QString systemLanguage = UBPlatformUtils::systemLanguage();
language = "en_US"; language = checkLanguageAvailabilityForSankore(systemLanguage);
//fallback if no translation are available }
}
else{ if(language.isEmpty()){
mApplicationTranslator = new QTranslator(this); language = "en_US";
mQtGuiTranslator = new QTranslator(this); //fallback if no translation are available
}
else{
mApplicationTranslator = new QTranslator(this);
mQtGuiTranslator = new QTranslator(this);
mApplicationTranslator->load(UBPlatformUtils::translationPath(QString("sankore_"),language)); mApplicationTranslator->load(UBPlatformUtils::translationPath(QString("sankore_"),language));
installTranslator(mApplicationTranslator); installTranslator(mApplicationTranslator);
QString qtGuiTranslationPath = UBPlatformUtils::translationPath("qt_", language);
mQtGuiTranslator->load(UBPlatformUtils::translationPath(QString("qt_"),language)); if(!QFile(qtGuiTranslationPath).exists()){
if(!mQtGuiTranslator->isEmpty()){ qtGuiTranslationPath = UBPlatformUtils::translationPath("qt_", language.left(2));
// checked because this translation could be not available if(!QFile(qtGuiTranslationPath).exists())
installTranslator(mQtGuiTranslator); qtGuiTranslationPath = "";
} }
else
qDebug() << "Qt gui translation in " << language << " are not available";
}
if(!qtGuiTranslationPath.isEmpty()){
qDebug() << "qtGuiTranslationPath " << qtGuiTranslationPath;
mQtGuiTranslator->load(qtGuiTranslationPath);
installTranslator(mQtGuiTranslator);
}
else
qDebug() << "Qt gui translation in " << language << " is not available";
}
QLocale::setDefault(QLocale(language)); QLocale::setDefault(QLocale(language));
qDebug() << "Running application in:" << language; qDebug() << "Running application in:" << language;

@ -119,10 +119,10 @@ class UBApplication : public QtSingleApplication
private: private:
void updateProtoActionsState(); void updateProtoActionsState();
void setupTranslator(QString forcedLanguage); void setupTranslators(QStringList args);
QList<QMenu*> mProtoMenus; QList<QMenu*> mProtoMenus;
bool mIsVerbose; bool mIsVerbose;
QString checkLanguageAvailabilityForSankore(QString& language);
protected: protected:
#if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA) #if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA)

Loading…
Cancel
Save