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. Getting the actual messages out of a QTranslator
Forum Updated to NodeBB v4.3 + New Features

Getting the actual messages out of a QTranslator

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

    Back in the day, it was possible to manually reach into a QTranslator and get all the messages inside it, for various uses (via a messages() member function, it looks like). It was useful for things such as handling translations of dynamically created menus and actions (i.e. ones that would not be automatically translated when all the other menus were, because only menus that exist at compile time get translated automatically).

    Nowadays, it looks like a lot of this functionality has been removed; if it doesn't work automatically, you're out of luck. Does anyone know a way to reach into the QTranslator and get the bi-directional messages? This would be particularly useful for reversing the lookup.

    The specific problem is that when the menus are generated, they are given text according to the current translation, so if they're created whilst in Japanese mode, their text is Japanese, and when the user switches to English, I have no way to look up that Japanese text and get the appropriate English.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why don't you use QEvent::LanguageChange ?

      From the documentation

      @
      void MyWidget::changeEvent(QEvent *event)
      {
      if (event->type() == QEvent::LanguageChange) {
      titleLabel->setText(tr("Document Title"));
      ...
      okPushButton->setText(tr("&OK"));
      } else
      QWidget::changeEvent(event);
      }@

      No need for revers lookups

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        bq. Why don’t you use QEvent::LanguageChange ?

        The menu-builder is not a QWidget; currently pushing the "Switch Language" button triggers the special handling for things that are not QWidgets and won't get the event; informing the Menu handlers that it's time to change language is not a problem.

        Keeping the text to be used on various different menus inside a changeEvent (or some other) function is just ugly. The menu objects should be in charge of themselves and hold their own data. Given that there can be a different number every time, I'd have to have each one add itself in some way as it went, along with a record of what its original English text is. I would much rather the objects simply have the capability to switch their display language themselves, internally, like nice encapsulated objects.

        I could give them a "retranslate" function of their own, but I would then have to permanently keep track of the original English wording; it would be nice if they could simply look at their own current display text and translate that.

        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