Skip to content
Permalink
Browse files

Merge pull request #7694 from signedav/trans_extends

Improvements of translation-featurs of .qgs project data
  • Loading branch information
m-kuhn committed Aug 24, 2018
2 parents 3b29e59 + 5ef0799 commit 04cdc9bf30f9fe9033ecce862b85b9a9029e521a
@@ -2218,4 +2218,10 @@ void QgsProjectProperties::onGenerateTsFileButton() const
{
QString l = cbtsLocale->currentData().toString();
QgsProject::instance()->generateTsFile( l );
QMessageBox::information( nullptr, tr( "General TS file generated" ), tr( "TS file generated with source language %1.\n"
"- open it with Qt Linguist\n"
"- translate strings\n"
"- save it with the postfix of the target language (eg. de)\n"
"- release to get qm file including postfix (eg. aproject_de.qm)\n"
"When you open it again in QGIS having set the target language (de), the project will be translated and saved with postfix (eg. aproject_de.qgs)." ).arg( l ) ) ;
}
@@ -479,10 +479,18 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
const QgsFields fields = vlayer->fields();
for ( const QgsField &field : fields )
{
QString fieldName;
if ( field.alias().isEmpty() )
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.name() );
fieldName = field.name();
else
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.alias() );
fieldName = field.alias();

translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), fieldName );

if ( field.editorWidgetSetup().type() == QStringLiteral( "ValueRelation" ) )
{
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( vlayer->id(), field.name() ), field.editorWidgetSetup().config().value( QStringLiteral( "Value" ) ).toString() );
}
}

//register formcontainers
@@ -2820,7 +2828,7 @@ void QgsProject::generateTsFile( const QString &locale )
{
QgsTranslationContext translationContext;
translationContext.setProject( this );
translationContext.setFileName( QStringLiteral( "%1/%2_%3.ts" ).arg( absolutePath(), baseName(), locale ) );
translationContext.setFileName( QStringLiteral( "%1/%2.ts" ).arg( absolutePath(), baseName() ) );

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

@@ -2834,5 +2842,11 @@ QString QgsProject::translate( const QString &context, const QString &sourceText
return sourceText;
}

return mTranslator->translate( context.toUtf8(), sourceText.toUtf8(), disambiguation, n );
QString result = mTranslator->translate( context.toUtf8(), sourceText.toUtf8(), disambiguation, n );

if ( result.isEmpty() )
{
return sourceText;
}
return result;
}
@@ -52,14 +52,11 @@ void QgsTranslationContext::registerTranslation( const QString &context, const Q

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() );
tsElement.setAttribute( QStringLiteral( "sourcelanguage" ), locale );
doc.appendChild( tsElement );

for ( const TranslatableObject &translatableObject : mTranslatableObjects )
@@ -81,8 +78,7 @@ void QgsTranslationContext::writeTsFile( const QString &locale )
messageElement.appendChild( sourceElement );

QDomElement translationElement = doc.createElement( QStringLiteral( "translation" ) );
QDomText translationText = doc.createTextNode( translatableObject.source );
translationElement.appendChild( translationText );
translationElement.setAttribute( QStringLiteral( "type" ), QStringLiteral( "unfinished" ) );
messageElement.appendChild( translationElement );
}

@@ -2035,6 +2035,10 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
QVariantMap optionsMap = QgsXmlUtils::readVariant( optionsElem ).toMap();
if ( widgetType == QStringLiteral( "ValueRelation" ) )
{
optionsMap[ QStringLiteral( "Value" ) ] = context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text(), fieldName ), optionsMap[ QStringLiteral( "Value" ) ].toString() );
}
QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( widgetType, optionsMap );
mFieldWidgetSetups[fieldName] = setup;
}
@@ -806,6 +806,13 @@
<string>Generate Project Translation File</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="sourceLanguageLabel">
<property name="text">
<string>Source language</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbtsLocale"/>
</item>
@@ -2950,6 +2957,7 @@
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
@@ -71,7 +71,7 @@ void TestQgsTranslateProject::cleanupTestCase()

//delete created ts file
QString tsFileName( TEST_DATA_DIR );
tsFileName = tsFileName + "/project_translation/points_translation_de.ts";
tsFileName = tsFileName + "/project_translation/points_translation.ts";
QFile tsFile( tsFileName );
tsFile.remove();
}
@@ -99,7 +99,7 @@ void TestQgsTranslateProject::createTsFile()

//check if ts file is created
QString tsFileName( TEST_DATA_DIR );
tsFileName = tsFileName + "/project_translation/points_translation_de.ts";
tsFileName = tsFileName + "/project_translation/points_translation.ts";
QFile tsFile( tsFileName );
QVERIFY( tsFile.exists() );

0 comments on commit 04cdc9b

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