Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Translations with subprojects
Qt 6.11 is out! See what's new in the release blog

Translations with subprojects

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 3 Posters 519 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    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_translations
    

    it 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

    1 Reply Last reply
    0
    • O Offline
      O Offline
      OdinUci
      wrote on last edited by
      #2

      hi please how can I make a filter to a tree in qt c++ simple rudimentary

      jsulmJ 1 Reply Last reply
      0
      • O OdinUci

        hi please how can I make a filter to a tree in qt c++ simple rudimentary

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @OdinUci What does your question have to do with OPs question?
        Please open your own thread and formulate your question better.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • D Offline
          D Offline
          django.Reinhard
          wrote on last edited by
          #4

          Hi,

          in case someone has similar problems - here's how I solved it:
          My CMakeList.txt has 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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved