@@ -366,6 +366,7 @@ QgsProject::QgsProject( QObject *parent )
366
366
connect ( mLayerStore .get (), &QgsMapLayerStore::allLayersRemoved, this , &QgsProject::removeAll );
367
367
connect ( mLayerStore .get (), &QgsMapLayerStore::layersAdded, this , &QgsProject::layersAdded );
368
368
connect ( mLayerStore .get (), &QgsMapLayerStore::layerWasAdded, this , &QgsProject::layerWasAdded );
369
+ connect ( QgsApplication::instance (), &QgsApplication::requestForTranslatableObjects, this , &QgsProject::registerTranslatableObjects );
369
370
}
370
371
371
372
@@ -441,6 +442,14 @@ void QgsProject::setPresetHomePath( const QString &path )
441
442
setDirty ( true );
442
443
}
443
444
445
+ void QgsProject::registerTranslatableObjects ( QgsTranslationContext *translationContext )
446
+ {
447
+ for ( auto layer : mRootGroup ->layerOrder () )
448
+ {
449
+ translationContext->registerTranslation ( QStringLiteral ( " project:layers:{layer_id}" ), layer->name () );
450
+ }
451
+ }
452
+
444
453
void QgsProject::setFileName ( const QString &name )
445
454
{
446
455
if ( name == mFile .fileName () )
@@ -487,6 +496,17 @@ QDateTime QgsProject::lastModified() const
487
496
}
488
497
}
489
498
499
+ QString QgsProject::absolutePath () const
500
+ {
501
+ if ( projectStorage () )
502
+ return QString ();
503
+
504
+ if ( mFile .fileName ().isEmpty () )
505
+ return QString (); // this is to protect ourselves from getting current directory from QFileInfo::absoluteFilePath()
506
+
507
+ return QFileInfo ( mFile .fileName () ).absolutePath ();
508
+ }
509
+
490
510
QString QgsProject::absoluteFilePath () const
491
511
{
492
512
if ( projectStorage () )
@@ -2698,3 +2718,38 @@ void QgsProject::setRequiredLayers( const QSet<QgsMapLayer *> &layers )
2698
2718
}
2699
2719
writeEntry ( QStringLiteral ( " RequiredLayers" ), QStringLiteral ( " Layers" ), layerIds );
2700
2720
}
2721
+
2722
+ void QgsProject::generateTsFile ()
2723
+ {
2724
+ QgsTranslationContext translationContext;
2725
+ translationContext.setProject ( this );
2726
+ translationContext.setFileName ( QStringLiteral ( " %1/%2.ts" ).arg ( absolutePath (), baseName () ) );
2727
+
2728
+ emit QgsApplication::instance ()->collectTranslatableObjects ( &translationContext );
2729
+
2730
+ translationContext.writeTsFile ();
2731
+ }
2732
+
2733
+ bool QgsProject::translate ( const QString &translationCode )
2734
+ {
2735
+ /*
2736
+ QgsTranslationContext translationContext;
2737
+ translationContext.setProject( this );
2738
+ translationContext.setFileName( filePath() );
2739
+
2740
+ QgsApplication::instance()->collectTranslatableObjects( &translationContext );
2741
+
2742
+ QTranslator projectTranslator( nullptr );
2743
+
2744
+ if ( projectTranslator.load( fileInfo().baseName() + translationCode, fileInfo().path() ) )
2745
+ {
2746
+ //translationContext.translations.projectTranslator.translate( )
2747
+ }
2748
+ else
2749
+ {
2750
+ return false;
2751
+ }
2752
+ */
2753
+ return true ;
2754
+ }
2755
+
0 commit comments