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. QGuiApplication::installTranslator has no effect
Forum Updated to NodeBB v4.3 + New Features

QGuiApplication::installTranslator has no effect

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 294 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.
  • C Offline
    C Offline
    Creaperdown
    wrote on last edited by
    #1

    I am trying to translate my application to german.

    Following the documentation, I have added qsTr() around the text that I am using, e.g.:

    Label {
                            id: welcomeText
                            Layout.alignment: Qt.AlignHCenter
                            Layout.topMargin: 24
                            text: qsTr("Welcome back!")
                            color: Style.colorText
                            font.bold: true
                            font.pointSize: Fonts.size26
                        }
    

    Then I have added the following to my CMakeLists.txt

    qt_add_translations(presentation TS_FILES librum_de.ts)
    add_dependencies(presentation presentation_lupdate)
    add_dependencies(presentation presentation_lrelease)
    add_dependencies(presentation update_translations)
    

    Which correctly generates the librum_de.ts file. I have edited it using the Linguist tool and added the missing translations and then recompiled my application which lead to the .qm file to be properly generated.

    Now in my main.cpp when trying to load it:

        QTranslator translator;
    
        qDebug() << translator.load(":/i18n/librum_de");
        qDebug() << QGuiApplication::installTranslator(&translator);
    

    Both the qDebug() statements give me true, thus it seems to load it just fine, but none of the text inside my application actually changes.

    Does someone have an idea

    jsulmJ 1 Reply Last reply
    0
    • C Creaperdown

      I am trying to translate my application to german.

      Following the documentation, I have added qsTr() around the text that I am using, e.g.:

      Label {
                              id: welcomeText
                              Layout.alignment: Qt.AlignHCenter
                              Layout.topMargin: 24
                              text: qsTr("Welcome back!")
                              color: Style.colorText
                              font.bold: true
                              font.pointSize: Fonts.size26
                          }
      

      Then I have added the following to my CMakeLists.txt

      qt_add_translations(presentation TS_FILES librum_de.ts)
      add_dependencies(presentation presentation_lupdate)
      add_dependencies(presentation presentation_lrelease)
      add_dependencies(presentation update_translations)
      

      Which correctly generates the librum_de.ts file. I have edited it using the Linguist tool and added the missing translations and then recompiled my application which lead to the .qm file to be properly generated.

      Now in my main.cpp when trying to load it:

          QTranslator translator;
      
          qDebug() << translator.load(":/i18n/librum_de");
          qDebug() << QGuiApplication::installTranslator(&translator);
      

      Both the qDebug() statements give me true, thus it seems to load it just fine, but none of the text inside my application actually changes.

      Does someone have an idea

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

      @Creaperdown said in QGuiApplication::installTranslator has no effect:

      QTranslator translator;

      Where exactly is this line located? Maybe translator goes out of scope and is deleted?

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

      C 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Creaperdown said in QGuiApplication::installTranslator has no effect:

        QTranslator translator;

        Where exactly is this line located? Maybe translator goes out of scope and is deleted?

        C Offline
        C Offline
        Creaperdown
        wrote on last edited by
        #3

        @jsulm Thank you, I didn't have that in mind at all. I extracted it into a function that I was calling from main, but I have just seen that the documentation says that it doesnt take ownership of it, so it indeed goes out of scope.

        Moving it back into the main function fixes it!

        1 Reply Last reply
        0
        • C Creaperdown has marked this topic as solved on

        • Login

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