From 464ed3c96f87bf9d58fd494b6b6b92d18e6cb935 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 5 Feb 2020 16:34:10 +0300 Subject: [PATCH] Refactor resource manager to avoid problem with French translations in Shaper, when salome is launched with --language option --- src/Qtx/QtxResourceMgr.cxx | 45 +++++++++++++++++++++++++++----------- src/Qtx/QtxResourceMgr.h | 2 ++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 4fa61bf0f..e415d024f 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -2686,6 +2686,35 @@ QString QtxResourceMgr::defaultLanguage() const return ""; } + +/*! + \brief Select language to be used. + \param preferableLanguage preferable language name (if empty, default language is used) +*/ +QString QtxResourceMgr::language( const QString& preferableLanguage ) const +{ + // first try to select preferable language probably specified via the parameter + QString lang = preferableLanguage; + + // then try default language; selection of default language can be redefined in successors + if ( lang.isEmpty() ) + lang = defaultLanguage(); + + // then try language as defined in the preferences files + if ( lang.isEmpty() ) + value( langSection(), "language", lang ); + + // finally try strongly hardcoded Ennglish + if ( lang.isEmpty() ) + { + lang = QString( "en" ); + qWarning() << "QtxResourceMgr: Language not specified. Assumed:" << lang; + } + + return lang; +} + + /*! \brief Load translation files according to the specified language. @@ -2705,28 +2734,18 @@ QString QtxResourceMgr::defaultLanguage() const see userFileName()). To avoid loading user settings, pass \c false as first parameter. \param pref parameter which defines translation context (for example, package name) - \param l language name + \param preferableLanguage language name \sa resSection(), langSection(), loadTranslators() */ -void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) +void QtxResourceMgr::loadLanguage( const QString& pref, const QString& preferableLanguage ) { initialize( true ); QMap substMap; substMap.insert( 'A', appName() ); - QString lang = l; - if ( lang.isEmpty() ) - lang = defaultLanguage(); - if ( lang.isEmpty() ) - value( langSection(), "language", lang ); - - if ( lang.isEmpty() ) - { - lang = QString( "en" ); - qWarning() << "QtxResourceMgr: Language not specified. Assumed:" << lang; - } + QString lang = language( preferableLanguage ); substMap.insert( 'L', lang ); diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index c70644cd8..5f9c1a2d0 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -178,6 +178,8 @@ public: void refresh(); + QString language( const QString& = QString() ) const; + protected: virtual QString defaultLanguage() const; -- 2.39.2