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. Qt translation get original string
Qt 6.11 is out! See what's new in the release blog

Qt translation get original string

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.7k Views 2 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
    MartinD
    wrote on last edited by
    #1

    Hi,
    I want to log a message without translating it and also I want to display translated message to user. Is it possible to achieve this and at the same time register the string to Qt translating system?

    Bad - This causes message not to be registered by Qt translating system:

    QString message = "Message";
    log(message);
    showMessageToUser(tr(message));
    

    Bad - This duplicates the string

    log("Message");
    showMessageToUser(tr("Message"));
    

    Bad - This logs translated version of the message - I want non translated.

    QString message = tr("Message");
    log(message);
    showMessageToUser(message);
    
    kshegunovK 1 Reply Last reply
    0
    • M MartinD

      Hi,
      I want to log a message without translating it and also I want to display translated message to user. Is it possible to achieve this and at the same time register the string to Qt translating system?

      Bad - This causes message not to be registered by Qt translating system:

      QString message = "Message";
      log(message);
      showMessageToUser(tr(message));
      

      Bad - This duplicates the string

      log("Message");
      showMessageToUser(tr("Message"));
      

      Bad - This logs translated version of the message - I want non translated.

      QString message = tr("Message");
      log(message);
      showMessageToUser(message);
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @MartinD
      As far as I know, the second "bad" is the least bad of all as it actually works. I think you're stuck with it.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        It's not as convenient as the tr() function but you can use the QT_TRANSLATE_NOOP macro for this. For example:

        void logIt(const char* str)
        {
           log(str);
           showMessageToUser(qApp->translate("", str));
        }
        

        Use it like this:

        logIt(QT_TRANSLATE_NOOP("", "Hello world!"));
        
        T 1 Reply Last reply
        5
        • Chris KawaC Chris Kawa

          It's not as convenient as the tr() function but you can use the QT_TRANSLATE_NOOP macro for this. For example:

          void logIt(const char* str)
          {
             log(str);
             showMessageToUser(qApp->translate("", str));
          }
          

          Use it like this:

          logIt(QT_TRANSLATE_NOOP("", "Hello world!"));
          
          T Offline
          T Offline
          Trian
          wrote on last edited by
          #4

          @Chris-Kawa That works well in both c++ and qml. Thanks

          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