Skip to content
Permalink
Browse files

[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 c2bd4b940bc8ed76f106f72126aa59bd711cc80d
Showing with 21 additions and 0 deletions.
  1. +15 −0 src/core/qgsapplication.cpp
  2. +5 −0 src/core/qgsapplication.h
  3. +1 −0 src/core/qgsexpressioncontext.cpp
@@ -48,6 +48,7 @@
#include <QIcon>
#include <QPixmap>
#include <QThreadPool>
#include <QLocale>

#ifndef Q_OS_WIN
#include <netinet/in.h>
@@ -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" );
@@ -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();

@@ -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 ) );

0 comments on commit c2bd4b9

Please sign in to comment.
You can’t perform that action at this time.