Results 1 to 8 of 8

Thread: Linguist and static strings

  1. #1
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Linguist and static strings

    Hi All ,

    I need to translate my application , everithing worked fine, till i had to translate static string array.

    I have a ".h" file with this decleratrion

    Qt Code:
    1. static QString vecBombType[4] = {
    2. QObject::trUtf8("None"),
    3. QObject::trUtf8("Explosive"),
    4. QObject::trUtf8("Flare"),
    5. QObject::trUtf8("Smoke")
    6. };
    7.  
    8. I'm inserting those string into QComboBox in a .cpp file
    9.  
    10. for ( int i=0; i < 4 i++ )
    11. {
    12. cboxBombType->insertItem( vecBombType[i], i);
    13. }
    To copy to clipboard, switch view to plain text mode 
    I've translated "Explosive" to something else , but keep on getting "Explosive" string.

    Beside this all translation are OK.

    How can i fix this?

  2. #2
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linguist and static strings

    Because static variables are initialized before main function is called, long before you load translators. You should have a function that initializes that array after translators are loaded.

    EDIT
    Or, you could use trUtf8 when using that strings. I'm not sure, but it may work.

    Qt Code:
    1. static QString vecBombType[4] = {
    2. QObject::trUtf8("None"),
    3. QObject::trUtf8("Explosive"),
    4. QObject::trUtf8("Flare"),
    5. QObject::trUtf8("Smoke")
    6. };
    7.  
    8. ...
    9.  
    10. for ( int i=0; i < 4 i++ )
    11. {
    12. cboxBombType->insertItem( trUtf8(vecBombType[i]), i);
    13. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Linguist and static strings

    Qt Code:
    1. static QString vecBombType[4] = {
    2. QT_TR_NOOP("None"),
    3. QT_TR_NOOP("Explosive"),
    4. QT_TR_NOOP("Flare"),
    5. QT_TR_NOOP("Smoke")
    6. };
    7.  
    8. for ( int i=0; i < 4 i++ ){
    9. cboxBombType->insertItem( tr(vecBombType[i]), i);
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Linguist and static strings

    tried , didn't work
    the static string is in a different header , i've placed it inside the project , ts file include this strings.
    Translating , releasing

    still same issue

  5. #5
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Linguist and static strings

    didn't work, bender ,thanks

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

    Default Re: Linguist and static strings

    If it's in a different header then you have to pass the context to translate() and QT_TR_NOOP(). Or move those strings into the same context.

  7. #7
    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: Linguist and static strings

    Just look at QT_TRANSLATE_NOOP() and QT_TR_NOOP() docs. They are very well documented and include clear examples.
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    Equilibrium (5th March 2008)

  9. #8
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Linguist and static strings

    founf what to do thanks to every one

Similar Threads

  1. tr() and static fields
    By drkbkr in forum Qt Programming
    Replies: 6
    Last Post: 5th June 2007, 17:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.