Skip to content

Commit 628292b

Browse files
committed
gui implementation
1 parent 2bfe229 commit 628292b

File tree

8 files changed

+78
-33
lines changed

8 files changed

+78
-33
lines changed

python/core/auto_generated/qgstranslationcontext.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Registers the ``string`` to be translated
6363
:param layerName: the name of the layer
6464
%End
6565

66-
void writeTsFile( );
66+
void writeTsFile( const QString &locale );
6767
%Docstring
6868
Writes the Ts-file
6969
%End

src/app/qgsprojectproperties.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,30 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
830830
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
831831
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );
832832

833+
//fill ts language checkbox
834+
//could possibly be taken from QgsOptions
835+
QString myI18nPath = QgsApplication::i18nPath();
836+
QDir myDir( myI18nPath, QStringLiteral( "qgis*.qm" ) );
837+
QStringList myFileList = myDir.entryList();
838+
QStringListIterator myIterator( myFileList );
839+
while ( myIterator.hasNext() )
840+
{
841+
QString myFileName = myIterator.next();
842+
843+
// Ignore the 'en' translation file, already added as 'en_US'.
844+
if ( myFileName.compare( QLatin1String( "qgis_en.qm" ) ) == 0 ) continue;
845+
846+
QString l = myFileName.remove( QStringLiteral( "qgis_" ) ).remove( QStringLiteral( ".qm" ) );
847+
848+
// QTBUG-57802: eo locale is improperly handled
849+
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
850+
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
851+
}
852+
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
853+
cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings->value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) );
854+
833855
connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::generateTsFileButton_clicked );
856+
834857
projectionSelectorInitialized();
835858
populateRequiredLayers();
836859
restoreOptionsBaseUi();
@@ -2194,5 +2217,6 @@ void QgsProjectProperties::setCurrentPage( const QString &pageWidgetName )
21942217

21952218
void QgsProjectProperties::generateTsFileButton_clicked()
21962219
{
2197-
QgsProject::instance()->generateTsFile( "de" );
2220+
QString l = cbtsLocale->currentData().toString();
2221+
QgsProject::instance()->generateTsFile( l );
21982222
}

src/app/qgsprojectproperties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
9292
//! A scale in the list of project scales changed
9393
void scaleItemChanged( QListWidgetItem *changedScaleItem );
9494

95-
//dave to document
95+
//! generate the ts file with the locale selected in the checkbox
9696
void generateTsFileButton_clicked();
9797

9898
/**

src/core/qgsproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ void QgsProject::generateTsFile( const QString &locale )
27952795

27962796
emit QgsApplication::instance()->collectTranslatableObjects( &translationContext );
27972797

2798-
translationContext.writeTsFile();
2798+
translationContext.writeTsFile( locale );
27992799
}
28002800

28012801
QString QgsProject::translate( const QString &context, const QString &sourceText, const char *disambiguation, int n )

src/core/qgstranslationcontext.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <QDomElement>
2121
#include <QDomDocument>
2222

23+
#include "qgssettings.h"
24+
2325
QgsTranslationContext::QgsTranslationContext()
2426
{}
2527

@@ -51,12 +53,16 @@ void QgsTranslationContext::registerTranslation( const QString &context, const Q
5153
mTranslatableObjects.append( translatableObject );
5254
}
5355

54-
void QgsTranslationContext::writeTsFile()
56+
void QgsTranslationContext::writeTsFile( const QString &locale )
5557
{
58+
QgsSettings settings;
59+
5660
//write xml
5761
QDomDocument doc( QStringLiteral( "TS" ) );
5862

5963
QDomElement tsElement = doc.createElement( QStringLiteral( "TS" ) );
64+
tsElement.setAttribute( QStringLiteral( "language" ), locale );
65+
tsElement.setAttribute( QStringLiteral( "sourcelanguage" ), settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString() );
6066
doc.appendChild( tsElement );
6167

6268
for ( TranslatableObject translatableObject : mTranslatableObjects )

src/core/qgstranslationcontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CORE_EXPORT QgsTranslationContext
8282
/**
8383
* Writes the Ts-file
8484
*/
85-
void writeTsFile( );
85+
void writeTsFile( const QString &locale );
8686

8787
private:
8888

src/ui/qgsprojectpropertiesbase.ui

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@
276276
<property name="geometry">
277277
<rect>
278278
<x>0</x>
279-
<y>0</y>
280-
<width>671</width>
281-
<height>783</height>
279+
<y>-147</y>
280+
<width>680</width>
281+
<height>923</height>
282282
</rect>
283283
</property>
284284
<layout class="QVBoxLayout" name="verticalLayout_8">
@@ -801,10 +801,22 @@
801801
</widget>
802802
</item>
803803
<item>
804-
<widget class="QPushButton" name="generateTsFileButton">
805-
<property name="text">
806-
<string>Generate TS File</string>
804+
<widget class="QGroupBox" name="groupBox_6">
805+
<property name="title">
806+
<string>Generate Project Translation File</string>
807807
</property>
808+
<layout class="QHBoxLayout" name="horizontalLayout_4">
809+
<item>
810+
<widget class="QComboBox" name="cbtsLocale"/>
811+
</item>
812+
<item>
813+
<widget class="QPushButton" name="generateTsFileButton">
814+
<property name="text">
815+
<string>Generate TS File</string>
816+
</property>
817+
</widget>
818+
</item>
819+
</layout>
808820
</widget>
809821
</item>
810822
<item>
@@ -856,8 +868,8 @@
856868
<rect>
857869
<x>0</x>
858870
<y>0</y>
859-
<width>579</width>
860-
<height>170</height>
871+
<width>580</width>
872+
<height>154</height>
861873
</rect>
862874
</property>
863875
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -931,8 +943,8 @@
931943
<rect>
932944
<x>0</x>
933945
<y>0</y>
934-
<width>284</width>
935-
<height>573</height>
946+
<width>285</width>
947+
<height>638</height>
936948
</rect>
937949
</property>
938950
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -1369,7 +1381,7 @@
13691381
<rect>
13701382
<x>0</x>
13711383
<y>0</y>
1372-
<width>136</width>
1384+
<width>120</width>
13731385
<height>100</height>
13741386
</rect>
13751387
</property>
@@ -1547,8 +1559,8 @@
15471559
<rect>
15481560
<x>0</x>
15491561
<y>0</y>
1550-
<width>165</width>
1551-
<height>57</height>
1562+
<width>155</width>
1563+
<height>52</height>
15521564
</rect>
15531565
</property>
15541566
<layout class="QVBoxLayout" name="verticalLayout_17">
@@ -1609,8 +1621,8 @@
16091621
<rect>
16101622
<x>0</x>
16111623
<y>0</y>
1612-
<width>671</width>
1613-
<height>2451</height>
1624+
<width>622</width>
1625+
<height>2646</height>
16141626
</rect>
16151627
</property>
16161628
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -2732,6 +2744,12 @@
27322744
</layout>
27332745
</widget>
27342746
<customwidgets>
2747+
<customwidget>
2748+
<class>QgsScrollArea</class>
2749+
<extends>QScrollArea</extends>
2750+
<header>qgsscrollarea.h</header>
2751+
<container>1</container>
2752+
</customwidget>
27352753
<customwidget>
27362754
<class>QgsCollapsibleGroupBox</class>
27372755
<extends>QGroupBox</extends>
@@ -2755,12 +2773,6 @@
27552773
<header>qgsopacitywidget.h</header>
27562774
<container>1</container>
27572775
</customwidget>
2758-
<customwidget>
2759-
<class>QgsScrollArea</class>
2760-
<extends>QScrollArea</extends>
2761-
<header>qgsscrollarea.h</header>
2762-
<container>1</container>
2763-
</customwidget>
27642776
<customwidget>
27652777
<class>QgsVariableEditorWidget</class>
27662778
<extends>QWidget</extends>

tests/src/core/testqgstranslateproject.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TestQgsTranslateProject : public QObject
4848

4949
void TestQgsTranslateProject::initTestCase()
5050
{
51-
//start application in english
51+
//start application in german
5252
QgsApplication::init();
5353
QgsApplication::initQgis();
5454

@@ -87,12 +87,10 @@ void TestQgsTranslateProject::cleanup()
8787
//not needed
8888
}
8989

90-
9190
void TestQgsTranslateProject::createTsFile()
9291
{
93-
//the project should be translated and renamed
94-
//so base is points_translation_de.qgs and german values
95-
//then we generate a ts file for spanish
92+
//the base is points_translation_de.qgs and with german values
93+
//then we generate a ts file for spanish and the ts file with additional es postfix is created
9694

9795
//create ts-file
9896
QgsProject::instance()->generateTsFile( "es" );
@@ -124,7 +122,7 @@ void TestQgsTranslateProject::createTsFile()
124122

125123
void TestQgsTranslateProject::translateProject()
126124
{
127-
//it should translate the project to german
125+
//with the qm file containing translation from en to de, the project should be in german and renamed with postfix .de
128126
QgsVectorLayer *points_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( "points_240d6bd6_9203_470a_994a_aae13cd9fa04" ) );
129127
QgsVectorLayer *lines_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( "lines_a677672a_bf5d_410d_98c9_d326a5719a1b" ) );
130128

@@ -147,6 +145,11 @@ void TestQgsTranslateProject::translateProject()
147145
//check if first relation name translated
148146

149147
//check if second relation name translated
148+
149+
QString deProjectFileName( TEST_DATA_DIR );
150+
deProjectFileName = deProjectFileName + "/project_translation/points_translation_de.qgs";
151+
QFile deProjectFile( deProjectFileName );
152+
QVERIFY( deProjectFile.exists() );
150153
}
151154

152155
QGSTEST_MAIN( TestQgsTranslateProject )

0 commit comments

Comments
 (0)