Results 1 to 11 of 11

Thread: Localization for dynamically generated text.

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

    Default Localization for dynamically generated text.

    Hi,
    I have a XML file which has the text for all the Widgets that i am using in my application.
    I read this XML file at runtime and set the text for my widgets.

    Now i want to create localization for these texts which are in that XML files.
    lupdate doesn't recognize the texts used to create ts files for this case.

    Literals String works fine like pushbutton->setText(tr("Hi"));

    But something like pushbutton->setText(strText);
    where strText is QString which contains the text from that XML file .
    lupdate doesn't recognize for latter text to create ts file .

    Any help would be appreciated.
    Thanks .

  2. #2
    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: Localization for dynamically generated text.

    You need to wrap all the possible literal strings into QT_TR_NOOP calls apart from using tr for the translation:
    Qt Code:
    1. QString FriendlyConversation::greeting(int type) {
    2. static const char *greeting_strings[] = {
    3. QT_TR_NOOP("Hello"),
    4. QT_TR_NOOP("Goodbye")
    5. };
    6. return tr(greeting_strings[type]);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Other than that I would suggest to apply an xsl transformation on your original xml file to make it conformant with Qt's .ts files. Then you just don't need lupdate.
    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. #3
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Localization for dynamically generated text.

    Thanks .
    Could you elaborate more on second point about XSL.

  4. #4
    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: Localization for dynamically generated text.

    Google for XSLT.
    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.


  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Localization for dynamically generated text.

    How do you imagine to have localized text from custom data? If text from file is none deterministic then it is impossible (extremely hard) to provide proper translations! For example see google translate.
    If you have well defined texts then IMHO you trying to do something strange what should be handled fully by Qt localization engine.
    Write what you are trying to do not how you try to achieve this.

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

    Default Re: Localization for dynamically generated text.

    I have some 50 files from which i read these texts.These are not the .cpp or .h files but the files which stores the text for some widgets.
    The way QT lupdate reads all the literals withen the file(.cpp or .h) wraped under tr() and creates .ts for it.
    In similar way i want some approch by which my texts from those 50 file be the part of ts file so that i can provide the translation for the same.

  7. #7
    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: Localization for dynamically generated text.

    So use XSLT or store your texts in a format compliant with .ts file structure.
    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. #8
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Localization for dynamically generated text.

    Sorry But thses are not the XML files but some format read by my application.It not only stores the text but the other widget information like height with color etc.
    I cant change these files either.

  9. #9
    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: Localization for dynamically generated text.

    So convert them. How many times do I have to repeat myself? Or build a custom backend for QTranslator around your files.
    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.


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

    Default Re: Localization for dynamically generated text.

    I may sound little foolish but how to build a custom backend for QTranslator around my files.

  11. #11
    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: Localization for dynamically generated text.

    You reimplement QTranslator::translate().
    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. Dynamically resize text
    By antialias_forum in forum Qt Quick
    Replies: 4
    Last Post: 6th May 2011, 23:37
  2. Real Time Localization System
    By oswalidos in forum General Programming
    Replies: 3
    Last Post: 22nd September 2009, 19:50
  3. work with web generated xml
    By emental86 in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2009, 13:51
  4. displaying Text in QTAble dynamically
    By raghvendramisra in forum Qt Programming
    Replies: 8
    Last Post: 31st August 2007, 10:47

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.