Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Translation approach for non-gui application with auto-generated code parts

    General and Desktop
    2
    4
    127
    Loading More Posts
    • 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
      devjb last edited by

      I'am developing a framework that consists of several qt-based backend libraries without a gui (frontend will follow later).

      The applications, that use those libraries contain a lot of sourcecode, which will be generated by a 3rd party code-preprocessor.

      In case those auto generated code modules contain strings (they do a lot), I want the code-generator to generate translation files for them, on a per module basis.

      What would be the workflow to get those translation files loaded at runtime for the corresponding source modules.

      Example (just what I think it should look like):

      1. Code generator provides:

        • concrete-foo.cpp
        • concrete-foo.h
        • concrete-foo-de.ts
        • concrete-foo-en.ts
      2. Backend library contains a fooLoader, which does stuff with the autogenerated source code parts.

      3. fooLoader will have a QString giveMeALocalizedString(someStringIndex) -method which I can use to access strings at runtime. That probably would have to lookup the *.ts files somehow.

      4. fooLoader will have a setLanguage(languageDescriptor)-method that shall switch the used language for it at runtime.

      The tutorials for QT I found so far for internationalization only cover cases where you have a Gui application and translate your whole application from one point on using a qtranslator attached to the qApplication.

      I feel that my needs are not covered by such an approach. But I have also not that much experience with qt's translation system.

      Do my above ideas sound ok? If yes, how should I implement the functionality in my application, my auto generated code and my consuming backend libs?

      Thank you in advance

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        It's QCoreApplication::installTranslator - the QTranslator example is a little bit misleading here since it uses a QApplication: https://doc.qt.io/qt-5/qtranslator.html#details

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 3
        • D
          devjb last edited by

          Thanks, so a QTranslator on the application level is the only possibility and users have to load all the available qm files delivered with the library manually in their application?

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by Christian Ehrlicher

            It's the same what Qt is doing - they're providing the qm files but you have to load them by your own.

            Qt has to stay free or it will die.

            1 Reply Last reply Reply Quote 3
            • First post
              Last post