Skip to content

Commit

Permalink
Merge pull request #7456 from signedav/translation_projects
Browse files Browse the repository at this point in the history
Translation of .qgs project data
  • Loading branch information
m-kuhn committed Aug 13, 2018
2 parents 6072350 + fea9de9 commit 70dcc33
Show file tree
Hide file tree
Showing 41 changed files with 1,954 additions and 64 deletions.
5 changes: 5 additions & 0 deletions python/core/auto_generated/layertree/qgslayertreegroup.sip.in
Expand Up @@ -127,6 +127,11 @@ Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
QgsLayerTreeGroup *findGroup( const QString &name );
%Docstring
Find group node with specified name. Searches recursively the whole sub-tree.
%End

QList<QgsLayerTreeGroup *> findGroups() const;
%Docstring
Find all group layer nodes
%End

static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
Expand Down
16 changes: 15 additions & 1 deletion python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -791,7 +791,6 @@ Do not include generated variables (like system name, user name etc.)
.. versionadded:: 3.0
%End


static void setCustomVariable( const QString &name, const QVariant &value );
%Docstring
Set a single custom expression variable.
Expand All @@ -808,6 +807,13 @@ The maximum number of concurrent connections per connections pool.
QGIS may in some situations allocate more than this amount
of connections to avoid deadlocks.

.. versionadded:: 3.4
%End

void collectTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Emits the signal to collect all the strings of .qgs to be included in ts file

.. versionadded:: 3.4
%End

Expand All @@ -829,6 +835,14 @@ Emitted whenever a custom global variable changes.
void nullRepresentationChanged();
%Docstring
\copydoc nullRepresentation()
%End

void requestForTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Emitted when project strings which require translation are being collected for inclusion in a .ts file.
In order to register translatable strings, connect to this signal and register the strings within the specified ``translationContext``.

.. versionadded:: 3.4
%End

};
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgseditformconfig.sip.in
Expand Up @@ -252,7 +252,7 @@ Sets type of feature form pop-up suppression after feature creation (overrides a
%End


void readXml( const QDomNode &node, QgsReadWriteContext &context );
void readXml( const QDomNode &node, QgsReadWriteContext &context );
%Docstring
Read XML information
Deserialize on project load
Expand All @@ -264,7 +264,7 @@ Write XML information
Serialize on project save
%End

QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent );
QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId = QString(), const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Deserialize drag and drop designer elements.
%End
Expand Down
57 changes: 56 additions & 1 deletion python/core/auto_generated/qgsproject.sip.in
Expand Up @@ -13,7 +13,7 @@



class QgsProject : QObject, QgsExpressionContextGenerator
class QgsProject : QObject, QgsExpressionContextGenerator, QgsProjectTranslator
{
%Docstring
Reads and writes project states.
Expand Down Expand Up @@ -135,6 +135,14 @@ Returns last modified time of the project file as returned by the file system (o
Returns full absolute path to the project file if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).

.. versionadded:: 3.2
%End

QString absolutePath() const;
%Docstring
Returns full absolute path to the project folder if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).

.. versionadded:: 3.2
%End

Expand Down Expand Up @@ -983,6 +991,28 @@ and it is mainly a hint for the user interface to protect users from removing la
in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here.

.. versionadded:: 3.2
%End

void generateTsFile( const QString &locale );
%Docstring
Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile()

.. versionadded:: 3.4
%End

virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const;

%Docstring
Translates the project with QTranslator and qm file

:return: the result string (in case there is no QTranslator loaded the sourceText)

:param context: describing layer etc.
:param sourceText: is the identifier of this text
:param disambiguation: it's the disambiguation
:param n: if -1 uses the appropriate form

.. versionadded:: 3.4
%End

signals:
Expand All @@ -1000,6 +1030,11 @@ just before a new project is read).
void readProject( const QDomDocument & );
%Docstring
Emitted when a project is being read.
%End

void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
%Docstring
Emitted when a project is being read. And passing the /a context
%End

void writeProject( QDomDocument & );
Expand Down Expand Up @@ -1335,6 +1370,26 @@ home path will be automatically determined from the project's file path.
.. seealso:: :py:func:`homePathChanged`

.. versionadded:: 3.2
%End

void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
%Docstring
Registers the containers that require translation into the translationContext.
This is a recursive function to get all the child containers.

:param translationContext: where the objects will be registered
:param parent: parent-container containing list of children
:param layerId: to store under the correct context

.. versionadded:: 3.4
%End

void registerTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Registers the objects that require translation into the ``translationContext``.
So there can be created a ts file with these values.

.. versionadded:: 3.4
%End

};
Expand Down
49 changes: 49 additions & 0 deletions python/core/auto_generated/qgsprojecttranslator.sip.in
@@ -0,0 +1,49 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojecttranslator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsProjectTranslator
{
%Docstring
Wherever an object of this class is available, the derived translate function can be called from.

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsprojecttranslator.h"
%End
public:


virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const = 0;
%Docstring
The derived translate() translates with QTranslator and qm file the sourceText.
It
:return: the result string and in case there is no QTranslator loaded, the sourceText.
This function can be called from wherever the QgsReadWriteContext is available.

:param context: describing layer etc.
:param sourceText: is the identifier of this text
:param disambiguation: it's the disambiguation
:param n: if -1 uses the appropriate form

.. versionadded:: 3.4
%End

virtual ~QgsProjectTranslator();
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojecttranslator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
15 changes: 15 additions & 0 deletions python/core/auto_generated/qgsreadwritecontext.sip.in
Expand Up @@ -98,7 +98,22 @@ Returns the stored messages and remove them
.. versionadded:: 3.2
%End

const QgsProjectTranslator *projectTranslator( ) const;
%Docstring
Returns the project translator

.. versionadded:: 3.4
%End

void setProjectTranslator( QgsProjectTranslator *projectTranslator );
%Docstring
Sets the project translator. Means it shouldn't conform mDefaultTranslator anymore.
It's usually the QgsProject where the function with the context is made and won't be changed anymore.

.. versionadded:: 3.4
%End

public:
};


Expand Down
3 changes: 2 additions & 1 deletion python/core/auto_generated/qgsrelation.sip.in
Expand Up @@ -35,11 +35,12 @@ class QgsRelation
Default constructor. Creates an invalid relation.
%End

static QgsRelation createFromXml( const QDomNode &node );
static QgsRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context );
%Docstring
Creates a relation from an XML structure. Used for reading .qgs projects.

:param node: The dom node containing the relation information
:param context: to pass project translator

:return: A relation
%End
Expand Down
77 changes: 77 additions & 0 deletions python/core/auto_generated/qgstranslationcontext.sip.in
@@ -0,0 +1,77 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstranslationcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsTranslationContext
{
%Docstring
Used for the collecting of strings from projects for translation and creation of ts files.

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgstranslationcontext.h"
%End
public:

QgsTranslationContext();
%Docstring
Constructor
%End

QgsProject *project() const;
%Docstring
Returns the project

.. seealso:: :py:func:`setProject`
%End

void setProject( QgsProject *project );
%Docstring
Sets the ``project`` being translated.

.. seealso:: :py:func:`project`
%End

QString fileName() const;
%Docstring
Returns the TS fileName

.. seealso:: :py:func:`setFileName`
%End

void setFileName( const QString &fileName );
%Docstring
Sets the ``fileName`` of the TS file

.. seealso:: :py:func:`fileName`
%End

void registerTranslation( const QString &context, const QString &source );
%Docstring
Registers the ``source`` to be translated. It's the text of the object needed to be translated.
The ``context`` defines in what context the object is used. Means layer name and sub category of object needed to be translated.
%End

void writeTsFile( const QString &locale );
%Docstring
Writes the Ts-file
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstranslationcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -366,6 +366,7 @@
%Include auto_generated/qgsvectorlayertools.sip
%Include auto_generated/qgsvectorsimplifymethod.sip
%Include auto_generated/qgssettings.sip
%Include auto_generated/qgsprojecttranslator.sip
%Include auto_generated/annotations/qgsannotation.sip
%Include auto_generated/annotations/qgsannotationmanager.sip
%Include auto_generated/annotations/qgshtmlannotation.sip
Expand Down Expand Up @@ -441,4 +442,5 @@
%Include auto_generated/layertree/qgslayertreeregistrybridge.sip
%Include auto_generated/qgsuserprofilemanager.sip
%Include auto_generated/symbology/qgsarrowsymbollayer.sip
%Include auto_generated/qgstranslationcontext.sip
%Include auto_generated/qgsuserprofile.sip
28 changes: 28 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -830,6 +830,28 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );

//fill ts language checkbox
QString i18nPath = QgsApplication::i18nPath();
QDir i18Dir( i18nPath, QStringLiteral( "qgis*.qm" ) );
const QStringList qmFileList = i18Dir.entryList();
for ( const QString &qmFile : qmFileList )
{
// Ignore the 'en' translation file, already added as 'en_US'.
if ( qmFile.compare( QLatin1String( "qgis_en.qm" ) ) == 0 ) continue;

QString qmFileName = qmFile;
QString l = qmFileName.remove( QStringLiteral( "qgis_" ) ).remove( QStringLiteral( ".qm" ) );

// QTBUG-57802: eo locale is improperly handled
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
}

cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) );

connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton );

projectionSelectorInitialized();
populateRequiredLayers();
restoreOptionsBaseUi();
Expand Down Expand Up @@ -2190,3 +2212,9 @@ void QgsProjectProperties::setCurrentPage( const QString &pageWidgetName )
}
}
}

void QgsProjectProperties::onGenerateTsFileButton() const
{
QString l = cbtsLocale->currentData().toString();
QgsProject::instance()->generateTsFile( l );
}
3 changes: 3 additions & 0 deletions src/app/qgsprojectproperties.h
Expand Up @@ -92,6 +92,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! A scale in the list of project scales changed
void scaleItemChanged( QListWidgetItem *changedScaleItem );

//! generate the ts file with the locale selected in the checkbox
void onGenerateTsFileButton() const;

/**
* Set WMS default extent to current canvas extent
*/
Expand Down

0 comments on commit 70dcc33

Please sign in to comment.