Results 1 to 3 of 3

Thread: Problem with dynamic translation

  1. #1
    Join Date
    Jul 2009
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with dynamic translation

    Hi all,

    I have a problem for dynamic translation. I am making a log system for an application and it must be international.

    I have 2 kinds of log messages, with and without parameter.
    Without parameter, the use of tr() fits perfectly.
    But with parameters i keep having the original untranslated string, whereas the lupdate and lrelease worked perfectly (neither warning nor error).

    Here is a sample of the code :
    Qt Code:
    1. // The messages are stored in the constructor of the object (a singleton class)
    2. Log::Log (){
    3. // _message is a map where the strings are stored, declared in the .hpp file
    4. map<unsigned int, QString>::iterator it = _message.begin();
    5. _message.insert(it,pair<unsigned int,QString>(1,QObject::tr(" Missing parameter ")));
    6. ...
    7. _message.insert(it,pair<unsigned int,QString>(51,QT_TR_NOOP(" Example message with %1")));
    8. _message.insert(it,pair<unsigned int,QString>(53,QT_TR_NOOP(" Message2 with %1 and %2")));
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

    In the same class I have a convert(int,list<QString>) function that takes a number and possible parameters and it returns the corresponding string :

    Qt Code:
    1. QString Log::convert(int numMsg, list<QString> param) {
    2. map<unsigned int,QString>::iterator it = _message.begin ();
    3. // If there are parameters
    4. switch (param.size ()){
    5. case 0 :
    6. return _message.find (numMsg); // Returning the corresponding string
    7. break;
    8. case 1 :
    9. // Function that finds the corresponding message with 1 parameter
    10. return fill1(param,it);
    11. break;
    12. case 2 :
    13. ....
    14.  
    15. }
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    And the fill1() function that is in the Log class too and that must perform the translation :

    Qt Code:
    1. QString Log::fill1 (list<QString> param, map<unsigned int,QString>::iterator it) {
    2. list<QString>::iterator iter = param.begin ();
    3. return QObject::tr ((*it).second.toLatin1 ()).arg(*iter);
    4. }
    To copy to clipboard, switch view to plain text mode 

    It works fine with the english version, but when i load a translator, the strings translated using the QT_TR_NOOP macro are still in english.
    Assuming i have neither warning nor error in QLinguist, and the number of translated sentence with lrelease corresponds exactly to the number of sentence i have, does anyone have an idea why the right sentences are not found ?

    I used a local map in the fill1 () function to try but it remained the same, i tried QT_TRANSLATE_NOOP () with context but nothing changed.




    .

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with dynamic translation

    QT_TR_NOOP is only a marker for the linguist tools. If your string shows up in linguist, that part was ok.
    If english translations work, and others do not, you should check if the translator for the other language was really loaded successfully.

  3. #3
    Join Date
    Jul 2009
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with dynamic translation

    Thanks for your reply but the load is successful because the other strings are translated, only the one passing through QT_TR_NOOP and later tr() remain in English.
    It is not English translation works and other don't, but the soft is made in English, and there is no problem with english messages, but when i want to translate it to another langage there is a problem.

    But the problem has just been solved thanks to a friend.
    I have to make my class inherit from QOBJECT, use the Q_OBJECT macro, and do not use QObject::tr() but tr() to be in the right context.

Similar Threads

  1. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  2. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  3. Dynamic number of QLabel
    By jd in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 17:09
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Runtime dynamic linking + Qt4 problem
    By _Ramirez_ in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2006, 14:28

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.