Skip to content
Permalink
Browse files

gui implementation

  • Loading branch information
signedav committed Jul 23, 2018
1 parent 2bfe229 commit 628292b974a520b4fd2a5eaab651d83472ab8e4e
@@ -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
@@ -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();
@@ -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 );
}
@@ -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();

/**
@@ -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 )
@@ -20,6 +20,8 @@
#include <QDomElement>
#include <QDomDocument>

#include "qgssettings.h"

QgsTranslationContext::QgsTranslationContext()
{}

@@ -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 )
@@ -82,7 +82,7 @@ class CORE_EXPORT QgsTranslationContext
/**
* Writes the Ts-file
*/
void writeTsFile( );
void writeTsFile( const QString &locale );

private:

@@ -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">
@@ -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>
@@ -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">
@@ -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">
@@ -1369,7 +1381,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>136</width>
<width>120</width>
<height>100</height>
</rect>
</property>
@@ -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">
@@ -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">
@@ -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>
@@ -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>
@@ -48,7 +48,7 @@ class TestQgsTranslateProject : public QObject

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

@@ -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" );
@@ -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" ) );

@@ -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 )

0 comments on commit 628292b

Please sign in to comment.
You can’t perform that action at this time.