issue on language

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 59abea3576
commit 8a6b3e3fa6
  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 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;
else{ }
QString systemLanguage = UBPlatformUtils::systemLanguage(); }
if(availablesTranslations.contains(systemLanguage,Qt::CaseInsensitive)) return QString("");
language = systemLanguage; }
else
qDebug() << "translation for system language " << systemLanguage << " not found"; void UBApplication::setupTranslators(QStringList args)
} {
QString forcedLanguage;
if(language.isEmpty()){ if(args.contains("-lang"))
language = "en_US"; forcedLanguage=args.at(args.indexOf("-lang") + 1);
//fallback if no translation are available else{
} QString setLanguage = UBSettings::settings()->appPreferredLanguage->get().toString();
else{ if(!setLanguage.isEmpty())
mApplicationTranslator = new QTranslator(this); forcedLanguage = setLanguage;
mQtGuiTranslator = new QTranslator(this); }
QStringList availablesTranslations = UBPlatformUtils::availableTranslations();
QString language("");
if(!forcedLanguage.isEmpty())
language = checkLanguageAvailabilityForSankore(forcedLanguage);
if(language.isEmpty()){
QString systemLanguage = UBPlatformUtils::systemLanguage();
language = checkLanguageAvailabilityForSankore(systemLanguage);
}
if(language.isEmpty()){
language = "en_US";
//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