Results 1 to 9 of 9

Thread: Problem when translating my app

  1. #1
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem when translating my app

    Hi all !

    I'm trying to translate my application. All is ok with the files which come from .ui . But with aller QMessageBox (just an exemple), I have a problem :

    here's the main.cpp :
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. ...
    4. else if(argc == 1)
    5. {
    6. // the translation is loaded in the contructor of ui_murefImpl (see below this code)
    7. ui_murefImpl window(0, &app);
    8. window.show();
    9.  
    10. // I'm doing this because I saw this in the ui.h file (and tr() && QApplication::translate() are too ineffective
    11. QPushButton hello(QApplication::translate("MainWindow", "Music", 0, QApplication::UnicodeUTF8));
    12. hello.resize(100, 30);
    13. hello.show();
    14.  
    15. return app.exec();
    16. }
    17. ....
    18. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ui_murefImpl::ui_murefImpl(QWidget *parent, QApplication *myApp) : QMainWindow(parent)
    2. {
    3. configure(myApp);
    4. }
    5.  
    6. void ui_murefImpl::configure(QApplication *myApp)
    7. {
    8. // all that is correct because the ui is translated !
    9. QTranslator translator;
    10. QString locale = QLocale::system().name();
    11. translator.load(QString("MuRef_") + locale);
    12. myApp->installTranslator(&translator);
    13. ...
    14. ui.setupUi(this);
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that (of course) the text in the button is not translated (but I do correctly all the other manipulations : lupdate, qtlinguist (made changements, saved), lrelease and launching the program).


    Thanks for reading !

    P.S.: I'm doing tests on a "hello button" because I don't want to recompile each time the whole app. But if it work on a QPushButton, it will still work with a QMessageBox...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by agent007se
    tr() && QApplication::translate() are too ineffective
    What makes you think so?

    Quote Originally Posted by agent007se
    but I do correctly all the other manipulations : lupdate, qtlinguist (made changements, saved), lrelease and launching the program).
    Can you see that button text when you open .ts file in Qt Linguist?

  3. #3
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by jacek
    What makes you think so?
    For the best reason : I tested before asking !

    Quote Originally Posted by jacek
    Can you see that button text when you open .ts file in Qt Linguist?
    For sure I can (if not, how could I translate it since I use Qt Linguist ?).

    Note : it appears in the context "MainWindow" and the source text panel is "Music" and I 'translated' it to "No music".

    Edit :
    this is a MINIMAL .pro file (I just want to translate the button, that will be a nice beginning !)
    Qt Code:
    1. TEMPLATE = app
    2. TARGET +=
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. # Input
    7. HEADERS +=
    8. FORMS += muref.ui
    9. SOURCES += main.cpp
    10. TRANSLATIONS += MuRef_fr.ts
    To copy to clipboard, switch view to plain text mode 


    when I try with tr() I got this error :
    main.cpp:23: error: `tr' undeclared (first use this function)
    main.cpp:23: error: (Each undeclared identifier is reported only once for each function it appears in.)
    :: === Build finished: 2 errors, 0 warnings ===
    Last edited by agent007se; 31st July 2006 at 19:40.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by agent007se
    For the best reason : I tested before asking
    And why it isn't effective?

    Quote Originally Posted by agent007se
    it appears in the context "MainWindow" and the source text panel is "Music" and I 'translated' it to "No music".
    Are you sure that your application loads the newest .qm file?

    when I try with tr() I got this error :
    tr() is a static method of QObject class.
    Qt Code:
    1. QPushButton hello( QObject::tr( "Music" ) );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by jacek
    And why it isn't effective?
    Because it doesn't work in my case ! (and of course I have a problem because that's very useful functions... there's no doubt about this)
    Quote Originally Posted by jacek
    Are you sure that your application loads the newest .qm file?
    How can I be ? There's only one .qm file and thus if it load the ui translation, it must load the others... (I don't really know about this).

    Quote Originally Posted by jacek
    tr() is a static method of QObject class.
    Qt Code:
    1. QPushButton hello( QObject::tr( "Music" ) );
    To copy to clipboard, switch view to plain text mode 
    Correct ! I understood that while I was reading the chapter 15 (internationalisation) of the Qt 3 online book !

    edit : of course, I deleted the .ts and the .qm and made new ones to be sure that is a "proper" translation but that didn't change anything to my problem ! Do you need more source code or screenshots ?
    Last edited by agent007se; 31st July 2006 at 22:38.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by agent007se
    Because it doesn't work in my case
    Ah, OK. "too ineffective" == "doesn't work in my case"

    Quote Originally Posted by agent007se
    There's only one .qm file and thus if it load the ui translation, it must load the others...
    Then delete that file, start your application and check if no translation was loaded, create a new .qm file and check your application again.

  7. #7
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by jacek
    Ah, OK. "too ineffective" == "doesn't work in my case"
    Yes I'm sorry English isn't my native language thus sometimes I may use some incorrect way of putting things togheter but I try to be at least readable .

    Quote Originally Posted by jacek
    Then delete that file, start your application and check if no translation was loaded, create a new .qm file and check your application again.
    Ok I'll try that tomorrow ! (it's midnight here (Beligum))

    Already thanks for trying to help me that's not the first time !

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    I've just took another look on your configure() method. You create the translator on the stack, so it gets destroyed when configure() returns.

    It should be:
    Qt Code:
    1. void ui_murefImpl::configure(QApplication *myApp)
    2. {
    3. QTranslator *translator= new QTranslator();
    4. ...
    5. translator->load(QString("MuRef_") + locale);
    6. myApp->installTranslator( translator );
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to jacek for this useful post:

    agent007se (31st July 2006)

  10. #9
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when translating my app

    Quote Originally Posted by jacek
    I've just took another look on your configure() method. You create the translator on the stack, so it gets destroyed when configure() returns.

    It should be:
    Qt Code:
    1. void ui_murefImpl::configure(QApplication *myApp)
    2. {
    3. QTranslator *translator= new QTranslator();
    4. ...
    5. translator->load(QString("MuRef_") + locale);
    6. myApp->installTranslator( translator );
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    Yes yes yes !!! That works thanks a lot !

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. problem translating & rotating text
    By impeteperry in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2006, 19:17
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.