Skip to content

Commit

Permalink
gui implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Aug 7, 2018
1 parent 2bfe229 commit 628292b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 33 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgstranslationcontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Registers the ``string`` to be translated
:param layerName: the name of the layer
%End

void writeTsFile( );
void writeTsFile( const QString &locale );
%Docstring
Writes the Ts-file
%End
Expand Down
26 changes: 25 additions & 1 deletion src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,30 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );

//fill ts language checkbox
//could possibly be taken from QgsOptions
QString myI18nPath = QgsApplication::i18nPath();
QDir myDir( myI18nPath, QStringLiteral( "qgis*.qm" ) );
QStringList myFileList = myDir.entryList();
QStringListIterator myIterator( myFileList );
while ( myIterator.hasNext() )
{
QString myFileName = myIterator.next();

// Ignore the 'en' translation file, already added as 'en_US'.
if ( myFileName.compare( QLatin1String( "qgis_en.qm" ) ) == 0 ) continue;

QString l = myFileName.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( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
}
cbtsLocale->addItem( QIcon( QString( ":/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::generateTsFileButton_clicked );

projectionSelectorInitialized();
populateRequiredLayers();
restoreOptionsBaseUi();
Expand Down Expand Up @@ -2194,5 +2217,6 @@ void QgsProjectProperties::setCurrentPage( const QString &pageWidgetName )

void QgsProjectProperties::generateTsFileButton_clicked()
{
QgsProject::instance()->generateTsFile( "de" );
QString l = cbtsLocale->currentData().toString();
QgsProject::instance()->generateTsFile( l );
}
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! A scale in the list of project scales changed
void scaleItemChanged( QListWidgetItem *changedScaleItem );

//dave to document
//! generate the ts file with the locale selected in the checkbox
void generateTsFileButton_clicked();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ void QgsProject::generateTsFile( const QString &locale )

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

translationContext.writeTsFile();
translationContext.writeTsFile( locale );
}

QString QgsProject::translate( const QString &context, const QString &sourceText, const char *disambiguation, int n )
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgstranslationcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <QDomElement>
#include <QDomDocument>

#include "qgssettings.h"

QgsTranslationContext::QgsTranslationContext()
{}

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

void QgsTranslationContext::writeTsFile()
void QgsTranslationContext::writeTsFile( const QString &locale )
{
QgsSettings settings;

//write xml
QDomDocument doc( QStringLiteral( "TS" ) );

QDomElement tsElement = doc.createElement( QStringLiteral( "TS" ) );
tsElement.setAttribute( QStringLiteral( "language" ), locale );
tsElement.setAttribute( QStringLiteral( "sourcelanguage" ), settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString() );
doc.appendChild( tsElement );

for ( TranslatableObject translatableObject : mTranslatableObjects )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgstranslationcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CORE_EXPORT QgsTranslationContext
/**
* Writes the Ts-file
*/
void writeTsFile( );
void writeTsFile( const QString &locale );

private:

Expand Down
54 changes: 33 additions & 21 deletions src/ui/qgsprojectpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>783</height>
<y>-147</y>
<width>680</width>
<height>923</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
Expand Down Expand Up @@ -801,10 +801,22 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="generateTsFileButton">
<property name="text">
<string>Generate TS File</string>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Generate Project Translation File</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QComboBox" name="cbtsLocale"/>
</item>
<item>
<widget class="QPushButton" name="generateTsFileButton">
<property name="text">
<string>Generate TS File</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
Expand Down Expand Up @@ -856,8 +868,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>579</width>
<height>170</height>
<width>580</width>
<height>154</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -931,8 +943,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>284</width>
<height>573</height>
<width>285</width>
<height>638</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1369,7 +1381,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>136</width>
<width>120</width>
<height>100</height>
</rect>
</property>
Expand Down Expand Up @@ -1547,8 +1559,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>165</width>
<height>57</height>
<width>155</width>
<height>52</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
Expand Down Expand Up @@ -1609,8 +1621,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>2451</height>
<width>622</width>
<height>2646</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -2732,6 +2744,12 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
Expand All @@ -2755,12 +2773,6 @@
<header>qgsopacitywidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
Expand Down
15 changes: 9 additions & 6 deletions tests/src/core/testqgstranslateproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TestQgsTranslateProject : public QObject

void TestQgsTranslateProject::initTestCase()
{
//start application in english
//start application in german
QgsApplication::init();
QgsApplication::initQgis();

Expand Down Expand Up @@ -87,12 +87,10 @@ void TestQgsTranslateProject::cleanup()
//not needed
}


void TestQgsTranslateProject::createTsFile()
{
//the project should be translated and renamed
//so base is points_translation_de.qgs and german values
//then we generate a ts file for spanish
//the base is points_translation_de.qgs and with german values
//then we generate a ts file for spanish and the ts file with additional es postfix is created

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

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

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

//check if second relation name translated

QString deProjectFileName( TEST_DATA_DIR );
deProjectFileName = deProjectFileName + "/project_translation/points_translation_de.qgs";
QFile deProjectFile( deProjectFileName );
QVERIFY( deProjectFile.exists() );
}

QGSTEST_MAIN( TestQgsTranslateProject )
Expand Down

0 comments on commit 628292b

Please sign in to comment.