Translations with subprojects
-
Hi,
I migrated a project from Qt5 to Qt6 and read about Qts translation support. But when I issue the command from docs
cmake --build . --target update_translationsit handles only files from top-level project.
My project has many plugins, which I treat as deployable units, which means, each plugin has its own resources and of cause its own ts-files.How can I use cmake to handle translation command on all subdirectories as well?
I have subdirectories, which contain no sources just CMakefiles for other subdirectories. So iterating over subdirectory definitions is not the solution.
I guess, I could handle it with scripting, but I would prefer a solution that works with cmake.
Any help is appreciated
-
Hi,
in case someone has similar problems - here's how I solved it:
MyCMakeList.txthas these statements:set(TS_FILES i18n/MyApp_de_DE.ts) set(PROJECT_SOURCES src/main.cpp src/MainWindow.h src/MainWindow.cpp src/MainControl.h src/MainControl.cpp src/MainWindow.ui ${TS_FILES} ) qt_add_executable(MyApp MANUAL_FINALIZATION ${PROJECT_SOURCES} AppResources.qrc ) add_subdirectory(src/libModel) add_subdirectory(src/libService) add_subdirectory(src/plugins)plugins directory does not contain any sources but more subdirectories ...
I wrote a perlscript that reads CMakeList.txt and works based on the found informations. It successfully populated the ts-files declared in the plugins.
#!/usr/bin/perl # # script to handle translatable texts in projects with nested subprojects # use Cwd; sub readCMake { my $fp; my $rv; my @src, @dirs; open($fp, 'CMakeLists.txt') or die('OUPS - can not open cmake configuration!'."\n"); while (my $line = <$fp>) { if ($line =~ /set\(\s*TS_FILES/) { print('found TS_FILES -->'.$line."\n"); my @parts = split(/\(|\s+|\)/, $line); $rv->{'fnTS'} = $parts[2] if -e $parts[2]; } elsif ($line =~ /set\(\s*PROJECT_SOURCES/) { print('found PS -->'.$line."\n"); while (my $fnSrc = <$fp>) { $fnSrc =~ s/^\s*(\S+?)\s*$/$1/; push(@src, $fnSrc) if -e $fnSrc; last if $fnSrc =~/\)/; } } elsif ($line =~ /add_subdirectory\((.*?)\)/) { my $d = $1; $d = cwd().'/'.$d if not $d =~ /^\//; push(@dirs, $d); } } close($fp); $rv->{'src'} = \@src; $rv->{'dirs'} = \@dirs; return $rv; } sub scan { my $cfg = shift; my $cmd = 'lupdate '.join(' ', @{$cfg->{'src'}}).' -ts '.$cfg->{'fnTS'}; print('cmd: '.$cmd."\n"); system($cmd); } # # main # autoflush STDOUT 1; my $base = cwd(); my $work = readCMake(); print('TS-File: '.$work->{'fnTS'}."\n"); foreach (@{$work->{'src'}}) { print('source file: '.$_."\n"); } scan($work); foreach (@{$work->{'dirs'}}) { my $d = $_; print('sub-dir: '.$d."\n"); chdir($d); my $wSub = readCMake(); scan($wSub); }Cheers