Results 1 to 20 of 25

Thread: How to tranlaste #define and text from file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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.


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.