issue on language

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 59abea3576
commit 8a6b3e3fa6
  1. 70
      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,22 +199,41 @@ UBApplication::~UBApplication()
staticMemoryCleaner = 0; staticMemoryCleaner = 0;
} }
void UBApplication::setupTranslator(QString forcedLanguage) QString UBApplication::checkLanguageAvailabilityForSankore(QString &language)
{ {
QStringList availablesTranslations = UBPlatformUtils::availableTranslations(); QStringList availableTranslations = UBPlatformUtils::availableTranslations();
QString language(""); if(availableTranslations.contains(language,Qt::CaseInsensitive))
if(!forcedLanguage.isEmpty()){ return language;
if(availablesTranslations.contains(forcedLanguage,Qt::CaseInsensitive)) else{
language = forcedLanguage; if(language.length() > 2){
else QString shortLanguageCode = language.left(2);
qDebug() << "forced language " << forcedLanguage << " not available"; if(availableTranslations.contains(shortLanguageCode,Qt::CaseInsensitive))
return shortLanguageCode;
}
}
return QString("");
} }
void UBApplication::setupTranslators(QStringList args)
{
QString forcedLanguage;
if(args.contains("-lang"))
forcedLanguage=args.at(args.indexOf("-lang") + 1);
else{ else{
QString setLanguage = UBSettings::settings()->appPreferredLanguage->get().toString();
if(!setLanguage.isEmpty())
forcedLanguage = setLanguage;
}
QStringList availablesTranslations = UBPlatformUtils::availableTranslations();
QString language("");
if(!forcedLanguage.isEmpty())
language = checkLanguageAvailabilityForSankore(forcedLanguage);
if(language.isEmpty()){
QString systemLanguage = UBPlatformUtils::systemLanguage(); QString systemLanguage = UBPlatformUtils::systemLanguage();
if(availablesTranslations.contains(systemLanguage,Qt::CaseInsensitive)) language = checkLanguageAvailabilityForSankore(systemLanguage);
language = systemLanguage;
else
qDebug() << "translation for system language " << systemLanguage << " not found";
} }
if(language.isEmpty()){ if(language.isEmpty()){
@ -236,17 +247,24 @@ void UBApplication::setupTranslator(QString forcedLanguage)
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())
qtGuiTranslationPath = "";
}
if(qtGuiTranslationPath.isEmpty()){
qDebug() << "qtGuiTranslationPath " << qtGuiTranslationPath;
mQtGuiTranslator->load(qtGuiTranslationPath);
installTranslator(mQtGuiTranslator); installTranslator(mQtGuiTranslator);
} }
else else
qDebug() << "Qt gui translation in " << language << " are not available"; 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