mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[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.
This commit is contained in:
parent
68e09d4c63
commit
c2bd4b940b
@ -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 ) );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user