Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using translatable strings in a static library
Forum Updated to NodeBB v4.3 + New Features

Using translatable strings in a static library

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 419 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?

    If that is the case how should this be handled? Should the static library project be set up to create .ts and .qm files that a .qrc file in the project for the executable picks up?

    ALternatively is there a way to run lupdate etc against an entire Visual Studio solution or group of VS projects?

    If the above aren't the best way to do it, please let me know what I should be doing.

    Thank you
    David

    Christian EhrlicherC 1 Reply Last reply
    0
    • PerdrixP Perdrix

      Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?

      If that is the case how should this be handled? Should the static library project be set up to create .ts and .qm files that a .qrc file in the project for the executable picks up?

      ALternatively is there a way to run lupdate etc against an entire Visual Studio solution or group of VS projects?

      If the above aren't the best way to do it, please let me know what I should be doing.

      Thank you
      David

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Perdrix said in Using translatable strings in a static library:

      Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?

      No, because there is nothing as "translation strings" somewhere - there are 'strings' which should be translated. In Qt tihs is done with the QObject::tr() function. But I don't see why one of them should not work in a static library.

      When you want to use a qrc file in a static lib then you should follow the documentation: https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      PerdrixP 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Perdrix said in Using translatable strings in a static library:

        Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?

        No, because there is nothing as "translation strings" somewhere - there are 'strings' which should be translated. In Qt tihs is done with the QObject::tr() function. But I don't see why one of them should not work in a static library.

        When you want to use a qrc file in a static lib then you should follow the documentation: https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        @Christian-Ehrlicher Translatable strings == stuff passed to tr()

        So should I simply add a file called (e.g.) kernel_translations.qrc to the static library project and list all the kernel.<language>.qm files for the static library in that file?

        Then, if I read the link you gave correctly I add:

        Q_INIT_RESOURCE(kernel_translations);
        

        When I come to load the translations, I currently do this to pick up the executables translations:

        translatorFileName = QLatin1String("DSS.");
        translatorFileName += language;
        qDebug() << "app translator filename: " << translatorFileName;
        //
        // Install the language if it actually exists.
        //
        if (theAppTranslator.load(translatorFileName, ":/i18n/"))
        {
        	app.installTranslator(&theAppTranslator);
        }
        

        How should I modify that to also load the ts files starting with "kernel"?

        Many thanks

        Christian EhrlicherC 1 Reply Last reply
        0
        • PerdrixP Perdrix

          @Christian-Ehrlicher Translatable strings == stuff passed to tr()

          So should I simply add a file called (e.g.) kernel_translations.qrc to the static library project and list all the kernel.<language>.qm files for the static library in that file?

          Then, if I read the link you gave correctly I add:

          Q_INIT_RESOURCE(kernel_translations);
          

          When I come to load the translations, I currently do this to pick up the executables translations:

          translatorFileName = QLatin1String("DSS.");
          translatorFileName += language;
          qDebug() << "app translator filename: " << translatorFileName;
          //
          // Install the language if it actually exists.
          //
          if (theAppTranslator.load(translatorFileName, ":/i18n/"))
          {
          	app.installTranslator(&theAppTranslator);
          }
          

          How should I modify that to also load the ts files starting with "kernel"?

          Many thanks

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Perdrix said in Using translatable strings in a static library:

          How should I modify that to also load the ts files starting with "kernel"?

          The same way - there is no difference, the only thing you have to do for static app is, as the doc says and you do - init the resources with Q_INIT_RESOURCE

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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