Results 1 to 5 of 5

Thread: lupdate and dynamic/loaded strings (how to get into TS file)

  1. #1
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question lupdate and dynamic/loaded strings (how to get into TS file)

    I have many strings/tokens in my code that come from external sources (DBs, files, network connections). All of these need to be translated as would a normal string. The documentation on lupdate is however kind of sparse/non-extant in this regards.

    What kind of file can I produce to get lupdate to see all the strings that it needs to translate? I suppose I could just generate a dummy CPP file. Yet surely other projects have this need and there is a standard way of doing this.


    Note that mostly the strings are not dynamic and I *can* generate a list of them. In some cases I have some truly dynamic strings, but that's another problem.

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

    Default Re: lupdate and dynamic/loaded strings (how to get into TS file)

    If you can generate a cpp file containing all the strings, then you can use QtGlobal::QT_TR_NOOP and QtGlobal::QT_TRANSLATE_NOOP. They just mark the strings to be translated.

  3. #3
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: lupdate and dynamic/loaded strings (how to get into TS file)

    Generating a CPP file does appear to be the most popular way of doing this.

    Thanks for pointing out QT_TRANSLATE_NOOP, that lets me specify an arbitrary context.

  4. #4
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: lupdate and dynamic/loaded strings (how to get into TS file)

    I have the exact same use case as mortoray. Since this thread is two years old, is there now a better way to accomplish this, or is the recommendation still to generate a dummy cpp file for lupdate to process? If so, would such a file only consist of the following?

    QT_TRANSLATE_NOOP("MyContext", "MyString1")
    QT_TRANSLATE_NOOP("MyContext", "MyString2")
    QT_TRANSLATE_NOOP("MyContext", "MyString3")
    // ...

    Or would it perhaps be possible to simply wrap the translatable text in the external resource file in QT_TRANSLATE_NOOP() and have lupdate process that file instead (thereby eliminating the need to generate a new cpp file every time the translatable text is changed in the external resource file)?

  5. #5
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: lupdate and dynamic/loaded strings (how to get into TS file)

    I found this old Qt doc that discusses this issue a bit: http://doc.qt.nokia.com/qq/qq03-swed....is.not.enough.

    It looks like a dummy cpp file that looks like this would work:

    #if 0
    qApp->translate( "MyContext", "MyString1" );
    qApp->translate( "MyContext", "MyString2" );
    qApp->translate( "MyContext", "MyString3" );
    #endif

    Has anyone successfully used this approach?

Similar Threads

  1. Gif plugin loaded but QImage cant read gif file.
    By spsingh in forum Installation and Deployment
    Replies: 0
    Last Post: 30th July 2010, 13:26
  2. Replies: 5
    Last Post: 7th May 2010, 13:54
  3. Dynamic widget creation from an XML-like file
    By ttvo in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2009, 22:15
  4. Replies: 13
    Last Post: 6th February 2009, 21:27
  5. Replies: 5
    Last Post: 22nd September 2006, 08:04

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.