Results 1 to 3 of 3

Thread: How to populate text entries to ts file from some other FIles (Localization)

  1. #1
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to populate text entries to ts file from some other FIles (Localization)

    Hi,
    I have an application which reads some file which has information about the widgets like below.

    Pushbutton
    tooltips :"THIS IS TO CREATE THE NAME"
    texts :"NAME"
    width:100
    height:200

    This at run time creates the QPUSHBUTTON with text as NAME and tooltip as "THIS IS TO CREATE THE NAME".

    Now I want to provide the localization for these texts and tooltips which are not written in .cpp or .h files.
    So running lupdate directly on .pro file wont work.
    So guys do you have any approch of populating all texts from such file's to .ts ? .

    Thanks....

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to populate text entries to ts file from some other FIles (Localization)

    You can use QT_TRANSLATE_NOOP macro:
    Qt Code:
    1. Pushbutton
    2. tooltips :QT_TRANSLATE_NOOP("ButtonTooltips","THIS IS TO CREATE THE NAME")
    3. texts :QT_TRANSLATE_NOOP("ButtonNames","NAME")
    4. width:100
    5. height:200
    To copy to clipboard, switch view to plain text mode 
    Then add this script to list of headers in .pro file, it will be parsed when you call lupdate <project file>.
    You can alter your parser to extract the tooltip text and button name from this script as well as translation context, and then translate the string, for example, like this (context and text are strings extracted from QT_TRANSLATE_NOOP macro from script):
    Qt Code:
    1. qApp->translate(context.toAscii().constData(),text.toAscii().constData());
    To copy to clipboard, switch view to plain text mode 
    It will work, I've done something like this some time ago.
    If you have better solution, I'll be happy to know it.

  3. #3
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to populate text entries to ts file from some other FIles (Localization)

    I wrote a script which extract all the tootip and text from my file and i wrote all those text in new file (say tr_translate.h ) under QT_TR_NLOOP() and then i run lupdate on tr_translate.h file .
    This way i don need to manually add

    #tooltips :QT_TRANSLATE_NOOP("ButtonTooltips","THIS IS TO CREATE THE NAME")
    #texts :QT_TRANSLATE_NOOP("ButtonNames","NAME")

    in every file of mine .

Similar Threads

  1. Replies: 1
    Last Post: 21st April 2011, 14:20
  2. Localization for dynamically generated text.
    By vaibhav in forum Qt Programming
    Replies: 10
    Last Post: 14th March 2011, 11:03
  3. Replies: 0
    Last Post: 16th April 2010, 11:16
  4. Replies: 1
    Last Post: 3rd September 2008, 14:16
  5. how to save sequences of text files and sound files
    By nagpalma in forum Qt Programming
    Replies: 8
    Last Post: 3rd July 2007, 00:06

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.