Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: How to tranlaste #define and text from file

  1. #1
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default How to tranlaste #define and text from file

    Hi,

    i have in .h file this:

    #define ITEM "textToTranslate"

    how can i translate it?


    and second, i have in file some text, which is loaded into QDraw. how can i transtale this text. text for translating is still same.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    Hi,

    i have in .h file this:

    #define ITEM "textToTranslate"

    how can i translate it?
    You could try:

    #define ITEM QT_TR_NOOP("textToTranslate")

    and then tr(ITEM) but in general using such defines in C++ is not a very good approach.

    Much cleaner solution is:

    Qt Code:
    1. const char * const ITEM = QT_TR_NOOP("textToTranslate");
    2.  
    3.  
    4. sth->setText(tr(ITEM));
    To copy to clipboard, switch view to plain text mode 


    and second, i have in file some text, which is loaded into QDraw.
    What is QDraw?

    how can i transtale this text. text for translating is still same.
    You'd need to manually teach your message catalog about the string to be translated. It's better to avoid such solutions. What do you need it for?

    A possible solution could be to reimplement QTranslator::translate().
    Last edited by wysota; 16th December 2013 at 14:38.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    stevocz (17th December 2013)

  4. #3
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    thank you for reply.

    i am try
    #define ITEM QT_TR_NOOP("textToTranslate")

    and then tr(ITEM)

    but doesnt work. textToTranslate missing in ts file.


    What is QDraw?
    sorry i mean in painter drawText

    i have one application which create xml file and text. this text is for show in second application
    Last edited by stevocz; 16th December 2013 at 14:01.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    thank you for reply.

    i am try
    #define ITEM QT_TR_NOOP("textToTranslate")

    and then tr(ITEM)

    but doesnt work. textToTranslate missing in ts file.
    So use the other possibility I gave you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    second possibility doesnt work too. after lupdate, textToTranslate missing in ts file.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    second possibility doesnt work too.
    Then it means you are doing something wrong, it should work just fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Oct 2013
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: How to tranlaste #define and text from file

    maybe i'm missing something here, but isn't it SUPPOSED to not be able to translate "textToTranslate" ? Without spaces its not really a word.

  9. #8
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    textToTranslat is only example. i have text with spaces and text with only one word.


    something is wrong, but i don't know what, because i can't transtale this:

    ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Ok"));
    ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
    application after start crash

    but other things work ok.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    application after start crash
    You probably get a null pointer from button().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    stevocz (17th December 2013)

  12. #10
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    i am stupid i call Ok button but i have Save button.


    but #define or const char * const ITEM still not work
    Last edited by stevocz; 17th December 2013 at 08:39.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    but #define od const char * const ITEM still not work
    Please post a minimal compilable example reproducing the problem. Make sure you have the file containing the QT_TR_NOOP macro explicitly added to your project file, otherwise lupdate won't scan it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #12
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    I am edited one example


    and QDialogButtonBox text is in .ts file but translate doesn' work. why?
    Attached Files Attached Files

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

    Default Re: How to tranlaste #define and text from file

    The translation mark is outside a context. Either put it in a context or use QT_TRANSLATE_NOOP instead of QT_TR_NOOP passing a context to the call. Make sure the same context is used with the tr() call.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:

    stevocz (17th December 2013)

  17. #14
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    can you fix it and send me back this application?

    because i am try this:

    const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("translateCategory", "Translate");

    and "Translate" is in .ts file, but in application text isn't changed.

    and please fix QDialogButtonBox

  18. #15
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to tranlaste #define and text from file

    maybe a stupid question, but why translate the QDialogButtonBox strings again?

    Those strings from Qt should already be translate for Qt.
    If they aren't, maybe the Qt translation catalogue wasn't loaded?
    See http://qt-project.org/doc/qt-4.8/i18...ng-translation

    Cheers,
    _

  19. #16
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    when i am erased .ts file and create new, QT_TRANSLATE_NOOP works ok

    this

    const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("translateCategory", "translate");
    ui.label_2->setText(QApplication::translate("translateCategor y",TEXT_TO_TRANSLATE));

    and this

    const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("QObject", "translate");
    ui.label_2->setText(QObject::tr(TEXT_TO_TRANSLATE));

    booth work.



    or best for this example

    const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("MainWindow", "translate");
    ui.label_2->setText(tr(TEXT_TO_TRANSLATE));

    work too.
    Last edited by stevocz; 17th December 2013 at 14:28.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    and "Translate" is in .ts file, but in application text isn't changed.
    Did you modify the respective tr() call to take data from the "translateCategory" context?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #18
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    yes, tr() is modified and works. now i must edit QDialogButtonBox.

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

    Default Re: How to tranlaste #define and text from file

    Quote Originally Posted by stevocz View Post
    yes, tr() is modified and works. now i must edit QDialogButtonBox.
    No, you just have to load the bundled message catalog for it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  23. #20
    Join Date
    May 2013
    Posts
    45
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    11

    Default Re: How to tranlaste #define and text from file

    but how? i am tried load QLibraryInfo but doesnt work

Similar Threads

  1. How to define a string marco in pro file
    By jevonwang in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 6th May 2013, 05:49
  2. QMake how to define install target of lib in the .pro file
    By thgis in forum Qt Tools
    Replies: 1
    Last Post: 15th April 2013, 12:59
  3. How to define a string in a .pro file
    By ChristineD in forum Newbie
    Replies: 4
    Last Post: 16th October 2012, 17:14
  4. qmake rc file define version
    By cafu1007 in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2012, 16:38
  5. Replies: 1
    Last Post: 3rd September 2008, 14:16

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.