Results 1 to 20 of 23

Thread: Switch QTranslator at runtime?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Switch QTranslator at runtime?

    There is no other way around than somehow identifying the translated parts (using regexp maybe?) and then setting the translated text again after passing it to tr().
    J-P Nurmi

  2. #2
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    Hi,

    sorry i don't know what are you mean. Can you give me a example please.

    Thanks in advance,

    Whitefurrows

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switch QTranslator at runtime?

    I think that in that situation you should tr() the whole html code and provide translations for it in the translation file.

    Qt Code:
    1. html->append(tr("<HTML><BODY>Text to be translated goes here<BR>\\n"
    2. "and you can even have arguments for it like this: %1</BODY></HTML>")
    3. .arg(tr("Some argument")));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    Hi,

    thank you, but this is not my problem. I have attach a example and hope you can help me.

    Thanks in advance,

    Whitefurrows
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switch QTranslator at runtime?

    And what is the difference between the two?

  6. #6
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    It’s not unconditional necessary to translate a argunent like arg(tr("Some argument")). I don’t know how can i translate a text that is set in a QTextEdit, can you help me?

    Tanks in advance,

    Whitefurrows

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switch QTranslator at runtime?

    Nobody says you have to have any arguments. I just said there is a possibility to do that, I didn't say you have to use it. If you have an append() call in your code, just recreate the contents using the same calls. If all those appends have a meaning, you can surely create a list of "commands" and refill the text edit with those commands (think of them as templates) translated to the appropriate language.

  8. #8
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    Hi,

    sorry i don't know how can i create a list of "commands" and refill the text edit with those commands. I have made a example that show you exact what i need, but is not so complex as the original. Please take a look at the example i have need a lot of time to make the example so easy for you. I hope you can help me.

    Thanks in advance,

    Whitefurrows
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switch QTranslator at runtime?

    I'm sorry, I just don't see the problem, you mean this?
    Qt Code:
    1. void MainWindow::showResult(int result)
    2. {
    3. QString html;
    4. html.append("<HTML><BODY>");
    5.  
    6. html.append("<table border=\"0\" width=\"100%\">");
    7. html.append("<tr><td align=\"center\">" + tr("The result is:") + "</td>");
    8. html.append("<td align=\"center\">" + QString().setNum(result) + "</td></tr>");
    9. html.append("</table>");
    10.  
    11. html.append("</HTML></BODY>");
    12.  
    13. ui.info->document()->setHtml(html);
    14. };
    To copy to clipboard, switch view to plain text mode 

    Just store the result somewhere and call this method again with the stored value when you need to retranslate the text edit.

    BTW. You can substitute
    Qt Code:
    1. QString().setNum(result)
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. QString::number(result)
    To copy to clipboard, switch view to plain text mode 
    .

  10. #10
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    Hi,

    thank you for your great help. i think i can do that, i store the result and call showResult again. What can i do in showInfo i set the text again but that wasn't translate. Can you help me?

    Thanks in advance,

    Whitefurrows

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switch QTranslator at runtime?

    You mean this?
    Qt Code:
    1. InfoView info(infos[i], this);
    To copy to clipboard, switch view to plain text mode 

    In this situation you have to call tr() here to do the translation and don't translate in setInfo(). You should only translate strings when they are displayed on screen (or shown to user in some other way). In setInfo() you should only mark strings for translation with QT_TR_NOOP().

  12. #12
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Switch QTranslator at runtime?

    Hi,

    thank you, that's fine. A last little questin. Now is all working, the only thing what's not OK is that:

    Qt Code:
    1. QT_TR_NOOP("Any information") + QString("<br><br>") + QT_TR_NOOP("for more text look next page");
    To copy to clipboard, switch view to plain text mode 

    What can i do to translate? I don't want translate the html code.

    Thanks in advance,

    Whitefurrows

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.