Skip to content

Commit

Permalink
Emit localeChanged signal when locale is changed (#45617)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joonalai authored and nyalldawson committed Dec 9, 2021
1 parent b3d6deb commit 8caad83
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -441,6 +441,13 @@ Returns the QGIS platform name, e.g., "desktop", "server", "qgis_process" or "ex
Returns the QGIS locale.

.. versionadded:: 3.0
%End

static void setLocale( QLocale locale );
%Docstring
Sets the QGIS locale.

.. versionadded:: 3.22
%End

static QString userThemesFolder();
Expand Down Expand Up @@ -1080,6 +1087,13 @@ In order to register translatable strings, connect to this signal and register t
.. versionadded:: 3.4
%End


void localeChanged();
%Docstring
Emitted when project locale has been changed.
%End


};


Expand Down
3 changes: 3 additions & 0 deletions src/app/main.cpp
Expand Up @@ -1034,6 +1034,9 @@ int main( int argc, char *argv[] )

QgsApplication myApp( argc, argv, myUseGuiFlag, QString(), QStringLiteral( "desktop" ) );

// Set locale to emit QgsApplication's localeChanged signal
myApp.setLocale( QLocale() );

//write the log messages written before creating QgsApplication
for ( const QString &preApplicationLogMessage : std::as_const( preApplicationLogMessages ) )
QgsMessageLog::logMessage( preApplicationLogMessage );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -1310,6 +1310,12 @@ QString QgsApplication::locale()
}
}

void QgsApplication::setLocale( QLocale locale )
{
QLocale::setDefault( locale );
emit instance()->localeChanged();
}

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

/**
* Sets the QGIS locale.
* \since QGIS 3.22
*/
static void setLocale( QLocale locale );

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

Expand Down Expand Up @@ -1043,6 +1049,13 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
void requestForTranslatableObjects( QgsTranslationContext *translationContext );


/**
* Emitted when project locale has been changed.
*/
void localeChanged();


private:

static void copyPath( const QString &src, const QString &dst );
Expand Down

0 comments on commit 8caad83

Please sign in to comment.