Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    10
    1891
    Loading More Posts
    • 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.
    • McLion
      McLion last edited by

      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 Reply Quote 0
      • Jeroentjehome
        Jeroentjehome last edited by

        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 Reply Quote 0
        • McLion
          McLion last edited by

          .. 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 Reply Quote 0
          • Jeroentjehome
            Jeroentjehome last edited by

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

            Greetz, Jeroen

            1 Reply Last reply Reply Quote 0
            • McLion
              McLion last edited by

              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 Reply Quote 0
              • Jeroentjehome
                Jeroentjehome last edited by

                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 Reply Quote 0
                • M
                  Moschops last edited by

                  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 Reply Quote 0
                  • McLion
                    McLion last edited by

                    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 Reply Quote 0
                    • M
                      Moschops last edited by

                      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 Reply Quote 0
                      • McLion
                        McLion last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post