Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] new global expression variable $qgis_locale
Returns current locale used by QGIS. By default this is current
system locale. If user enabled locale override in QGIS settings
overriden locale will be returned.
  • Loading branch information
alexbruy committed Jan 10, 2017
1 parent 68e09d4 commit c2bd4b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -48,6 +48,7 @@
#include <QIcon>
#include <QPixmap>
#include <QThreadPool>
#include <QLocale>

#ifndef Q_OS_WIN
#include <netinet/in.h>
Expand Down Expand Up @@ -902,6 +903,20 @@ QString QgsApplication::platform()
return sPlatformName;
}

QString QgsApplication::locale()
{
QSettings settings;
bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
if ( overrideLocale )
{
return settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
}
else
{
return QLocale::system().name().left( 2 );
}
}

QString QgsApplication::userThemesFolder()
{
return qgisSettingsDirPath() + QStringLiteral( "/themes" );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -241,6 +241,11 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static QString platform();

/** Returns the QGIS locale.
* @note added in QGIS 3.0
*/
static QString locale();

//! Returns the path to user's themes folder
static QString userThemesFolder();

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -524,6 +524,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::globalScope()
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_release_name" ), Qgis::QGIS_RELEASE_NAME, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_platform" ), QgsApplication::platform(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_os_name" ), QgsApplication::osName(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_locale" ), QgsApplication::locale(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_account_name" ), QgsApplication::userLoginName(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_full_name" ), QgsApplication::userFullName(), true ) );

Expand Down

0 comments on commit c2bd4b9

Please sign in to comment.