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. [Solved] Issue with translation tr("string")
Forum Updated to NodeBB v4.3 + New Features

[Solved] Issue with translation tr("string")

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.6k 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hi

    I am successfully using linguist for translating all the labels on buttons for a small app, which works perfectly.
    I am now trying to translate some strings by wrapping tr:

    @DebugShow(tr("IP address of module: ") + GetLocalIP(), DBG_DIRECT, Qt::black, Qt::white);@

    DebugShow is a function that uses the given arguments to format as simple html and send to a QPlainTextEdit which works perfect, just not translated.
    Linguist does show the string, I translated it, but the translation does not appear.
    Any idea?
    Thanks
    McL

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      I do not believe you are able to copy the string to each other with the + operator. To use the linquist you need to use .arg option:
      @
      QString MyString(tr("Your text here: %1).arg(AddedString));
      @

      Greetz, Jeroen

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        .. I've rerun lupdate and lrelease many times ..

        I've used a QPlainTextEdit because this is the easiest way to have the "latest" 100 (settable with maximumBlockcount) messages stored scrollable in FIFO style in a debugwindows and be able to have colored messages (foreground/background) and further attributes for grouping and showing importance.
        IMHO, this works perfect and is a good thing.

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi, See my editted last post. use the .arg option for QString.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            That is not the issue. Concatenate with the + works perfect. The issue is the same with this as well:

            @DebugShow(tr("BlaBlaBal"), DBG_DIRECT, Qt::black, Qt::white);@

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Does only this string not work? Or do all non gui string fail? If so, it would seem to be a install of your translator. Do you set the translator run-time in an menu action? Do you set it before MainWindow is created?
              Did you implement a languageEvent handler??

              Greetz, Jeroen

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

                Is the translator definitely installed? You have loaded it with the right translation file, and it didn't return any error values?

                1 Reply Last reply
                0
                • McLionM Offline
                  McLionM Offline
                  McLion
                  wrote on last edited by
                  #8

                  Jeroen,
                  That was the correct hint.

                  The calls like
                  @DebugShow(tr("BlaBlaBal"), DBG_DIRECT, Qt::black, Qt::white);@
                  are in the constructor:

                  @
                  QMainWindow(parent,Qt::FramelessWindowHint),
                  ui(new Ui::QTGUI_MainWindow),
                  video(this),
                  m_translator(0)
                  {
                  ui->setupUi(this);
                  .....
                  @

                  as well as being called later from code.
                  The calls later from code are working. It's just that the translator is not yet active when the MainWindow is created. I'll need to change this .. somehow.

                  From main:
                  @ MyApplication program(argc, argv);
                  QDesktopWidget *desk = program.desktop();
                  QTGUI_MainWindow window;

                  window.setGeometry(desk->availableGeometry());
                  window.setLanguage("fr_CH");
                  window.show();

                  return program.exec();@

                  setLanguage installs (or removes/reinstalls) the Translator.

                  Thanks so far.

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

                    In my code, I load the translator at the earliest opportunity; directly after the QApplication is created.

                    If your code to load the translator is part of the class function setLanguage, that's too late. Load the translator before creating your MainWindow.

                    1 Reply Last reply
                    0
                    • McLionM Offline
                      McLionM Offline
                      McLion
                      wrote on last edited by
                      #10

                      I've moved it to before the MainWindow is created ... and it now works :-)
                      Thank you guys!

                      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