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. i18n, translation failed, when use QObject::tr to global QString...

i18n, translation failed, when use QObject::tr to global QString...

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

    how to translate QString when it's global, eg.
    const QString xxx[] =
    { QObject::tr("test"),
    QObject::tr("test"),
    }

    it did appears in Liguist and i did translate it, but not work in app.
    thank you!

    raven-worxR 1 Reply Last reply
    0
    • O opengpu2

      how to translate QString when it's global, eg.
      const QString xxx[] =
      { QObject::tr("test"),
      QObject::tr("test"),
      }

      it did appears in Liguist and i did translate it, but not work in app.
      thank you!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @opengpu2
      have you installed a translator loading your translation file?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      O 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @opengpu2
        have you installed a translator loading your translation file?

        O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        @raven-worx of course i did. the tr("") QString in a Class which is derived from QObject and have Q_OBJECT marco in the header works fine...
        but the global did not work...

        raven-worxR 1 Reply Last reply
        0
        • O opengpu2

          @raven-worx of course i did. the tr("") QString in a Class which is derived from QObject and have Q_OBJECT marco in the header works fine...
          but the global did not work...

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @opengpu2
          then the global variable gets initialized before you install the translator.
          When a new translator gets installed all tr() calls need to be reevaluated, means need to get called again.
          Actually you need to listen to a QEvent::LanguageChange event (on the QApplication itself IIRC) and then update the values again.

          It probably works in a QObject class because you instantiate the class after you installed the translator?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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