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. [SOLVED] Translations in static library and their usage

[SOLVED] Translations in static library and their usage

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k 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
    David_Gil
    wrote on last edited by
    #1

    Hi!

    I have made a static library named QAstrologyLib, and I have translated the few strings it has into Catalan. Then I have written a little program that uses this library.

    I thought that the translations would be automatically included into the static library, but I have to point where they are, otherwise it doesn't find the translation:

    @int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QTranslator translator;
    translator.load("/home/david/devel/QASTROLOGYLIB/src/qastrologylib_ca");
    app.installTranslator(&translator);
    EphemerisList ephemerisList;
    ephemerisList.show();
    return app.exec();
    }@

    I could insert the translations as resources in the library, but then, what's the path I have to use from the program to load the translation, since they are the library's resources?

    Thank you very much!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      messi
      wrote on last edited by
      #2

      Hi David,
      an absolute path in your program is not a good design strategy. And why did you create an static lib instead of a dynamic lib?

      As you mention it would be better to add the translation file as resource. The URL is quite simple.
      Same like icons. ":/MyTranslations/qastrologylib_ca.qm"

      /MyTranslation/ is the prefix which you can choose freely.

      Best regards

      1 Reply Last reply
      0
      • D Offline
        D Offline
        David_Gil
        wrote on last edited by
        #3

        Hi!

        I created a static lib because it's so small and new that I can't expect anyone to have it installed. For some time, I want to be able to deploy my programs in one single file.

        I have added the translation files as resources in the QAstrologyLib project, with the prefix "/" and the name of the qrc file "i18n.qrc".

        Then, I discovered that I have to use "Q_INIT_RESOURCE":http://qt-project.org/doc/qt-4.8/qdir.html#Q_INIT_RESOURCE

        @#include <QApplication>
        #include <QTranslator>

        #include <QDebug>
        #include "ephemerislist.h"

        int main(int argc, char *argv[])
        {
        QApplication app(argc, argv);
        Q_INIT_RESOURCE(i18n);

        QTranslator translator;
        qDebug() << translator.load(":/qastrologylib_ca");
        app.installTranslator(&translator);
        
        EphemerisList ephemerisList;
        ephemerisList.show();
        
        return app.exec();
        

        }@

        Thank you for your advice :-)

        David Gil

        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