Results 1 to 4 of 4

Thread: Translating problem (file loaded, but the strings isn't tranlated)

  1. #1
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Translating problem (file loaded, but the strings isn't tranlated)

    I'm trying to translate my app and the only thing that i can translate is the Qt texts with loading "qt_pt.qm" but when I try to load my "app.qm" the text doesn't get translated.

    I've tried everything i know, but it isn't working.

    So, made another project and tried to translate words in Console App, same problem.

    Can you help me ?

    This is the .ts file:

    Qt Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!DOCTYPE TS>
    3. <TS version="2.0" language="pt" sourcelanguage="en">
    4. <context>
    5. <name></name>
    6. <message>
    7. <source>old</source>
    8. <translation>velho</translation>
    9. </message>
    10. <message>
    11. <source>novo</source>
    12. <translation>new</translation>
    13. </message>
    14. </context>
    15. </TS>
    To copy to clipboard, switch view to plain text mode 

    This is my code:

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QTranslator>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9. qDebug() << "loaded: " << tr->load("translator.qm", "C:\\C++\\Qt Projects\\Translator\\Translator");
    10.  
    11. qDebug() << "------------------";
    12. qDebug() << QObject::tr("old");
    13. qDebug() << QObject::tr("velho");
    14. qDebug() << QObject::tr("new");
    15. qDebug() << QObject::tr("novo");
    16. qDebug() << "------------------";
    17.  
    18. a.installTranslator(tr);
    19.  
    20. qDebug() << "------------------";
    21. qDebug() << QObject::tr("old");
    22. qDebug() << QObject::tr("velho");
    23. qDebug() << QObject::tr("new");
    24. qDebug() << QObject::tr("novo");
    25. qDebug() << "------------------";
    26.  
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

    and I get this output:

    Qt Code:
    1. loaded: true
    2. ------------------
    3. "old"
    4. "velho"
    5. "new"
    6. "novo"
    7. ------------------
    8. ------------------
    9. "old"
    10. "velho"
    11. "new"
    12. "novo"
    13. ------------------
    To copy to clipboard, switch view to plain text mode 

    It doesn't translate my text, link in my App, what I can do ?
    What is wrong in the code ?
    What I need to do to fix it ?

    (Using Qt 4.7.2)

  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: Translating problem (file loaded, but the strings isn't tranlated)

    File name should not be a problem, change context name to QObject and it should work.
    I've just tested your code and get this output:
    loaded: true
    ------------------
    "old"
    "velho"
    "new"
    "novo"
    ------------------
    ------------------
    "velho"
    "velho"
    "new"
    "new"
    ------------------
    .ts file:
    Qt Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!DOCTYPE TS>
    3. <TS version="2.0" language="pt" sourcelanguage="en">
    4. <context>
    5. <name>QObject</name>
    6. <message>
    7. <source>old</source>
    8. <translation>velho</translation>
    9. </message>
    10. <message>
    11. <source>novo</source>
    12. <translation>new</translation>
    13. </message>
    14. </context>
    15. </TS>
    To copy to clipboard, switch view to plain text mode 
    Btw if you call lupdate <project file name> you will get proper file ready for translating. Don't forget to call lrelease <project file name> after editing the .ts file.

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translating problem (file loaded, but the strings isn't tranlated)

    Qt Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!DOCTYPE TS>
    3. <TS version="2.0" language="pt" sourcelanguage="en">
    4. <context>
    5. <name>QObject</name>
    6. <message>
    7. <source>old</source>
    8. <translation>velho</translation>
    9. </message>
    10. <message>
    11. <source>novo</source>
    12. <translation>new</translation>
    13. </message>
    14. </context>
    15. </TS>
    To copy to clipboard, switch view to plain text mode 

    IMHO lines 11 and 12 are swapped. What you're saying is that the English WORD ("novo") has Portuguese translation ("new").

    Have you written this file by hands or using QtLinguist??
    Last edited by mcosta; 20th April 2011 at 11:54. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Translating problem (file loaded, but the strings isn't tranlated)

    stampede

    Thanks, it's worked, the context name was the problem ^^

    mcosta

    It's only for testing, this is why i've swapped the translations


    Thank you two for awsering ^^

Similar Threads

  1. Replies: 4
    Last Post: 9th August 2012, 21:08
  2. Replies: 0
    Last Post: 19th August 2007, 05:47
  3. Replies: 2
    Last Post: 13th September 2006, 09:11
  4. Problem when translating my app
    By agent007se in forum Newbie
    Replies: 8
    Last Post: 31st July 2006, 23:43
  5. problem translating & rotating text
    By impeteperry in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2006, 19:17

Tags for this Thread

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.