Results 1 to 12 of 12

Thread: Again a problem with Translation

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Again a problem with Translation

    Hi ( wysota do not despair ).
    I achieved to translate my mainwindow to other language reading settings ( at the moment I don't implemented a dynamic translation yet ).
    From my window I can open a 'settings' dialog pressing a button.
    I translated EVERY file having tr() but I don't understand why the dialog has not been translated.
    Must I do it in another way?

    Regards
    Franco Amato

  2. #2
    Join Date
    Oct 2010
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    can you be a bit more specific (show some code?) so we can help you?

    EDIT: lol dude, I just read your other posts. BE EXPLICIT IN EVERYTHING YOU SAY!! we are not mind readers

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    This is the problem:
    I read settings when the application starts. In the settings there is a language entry. In my case I can choose between english (en) and spanish (es).
    Every string in the source code is written in english and wrapped with tr(). So if I choose es in the configuration all in the main window is well translated from english to spanish ( I provide to the application a *.qm file produced with linguist ). The problem is that the dialog ( that I exec from the appplication is not translated ). The *.qm file contains also translations for the dialog strings and I don't understand why they are not well translated.
    I attach here a screenshoot translation.jpg explaining my problem.
    This is the better way I can explain my problem.
    Regards
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Again a problem with Translation

    Franco... some code, please. I will not repeat myself and will only ask for enough information this one time. If you don't provide enough information yourself, I will not respond to your post. If you are lucky enough, maybe someone else will.
    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
    Oct 2010
    Location
    Cracow,Bielsko-Biała/Polska
    Posts
    15
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: Again a problem with Translation

    Hello Franco.

    Do you have two *.qm files ? Or for application and dialogs you have exactly one *.qm file ?
    If you have more than one qm files, you have to create more QTranslator objects...

  6. #6
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    Quote Originally Posted by wysota View Post
    Franco... some code, please. I will not repeat myself and will only ask for enough information this one time. If you don't provide enough information yourself, I will not respond to your post. If you are lucky enough, maybe someone else will.
    Wysota I already gave to you all code last time. I don't know which code to provide.

    This is the ctor of my application:

    Qt Code:
    1. MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
    2. : QMainWindow(parent, flags),
    3. m_track1(""),
    4. m_track2(""),
    5. m_w1SourceDir(""),
    6. m_w2SourceDir(""),
    7. m_w1OutputDir(""),
    8. m_w2OutputDir(""),
    9. m_fileOneLoaded(false),
    10. m_fileTwoLoaded(false),
    11. m_trackListDlg(NULL)
    12. {
    13. setObjectName("MainWindow");
    14.  
    15. /* set window title */
    16. setWindowTitle("ECP Studio");
    17.  
    18. readSettings(); // <-- here I read settings ( also language entry )
    19.  
    20. QTranslator esTranslator;
    21. if( QString::compare(m_language,"es") == 0 )
    22. {
    23. esTranslator.load("ecpstudio_es");
    24. qApp->installTranslator(&esTranslator);
    25. }
    26.  
    27. /* create menu and status bar */
    28. createActions();
    29. createMenus();
    30. createToolBar();
    31. createStatusBar();
    32.  
    33. /* set the central widget */
    34. m_centralWidget = new CentralWidget( m_bgColor, m_wfColor, m_w1OutputDir, m_w2OutputDir, m_bgFile, m_mstep, m_sstep, m_loopInterval, this );
    35. setCentralWidget( m_centralWidget );
    36.  
    37. enableGlobalCommands( false );
    38.  
    39. connect( check, SIGNAL( stateChanged( int ) ), this, SLOT( uniqueFileChanged( int ) ) );
    40. connect( this, SIGNAL( synchSignal() ), m_centralWidget, SLOT( synchSlot()));
    41. connect( this, SIGNAL( globalPlaySignal() ), m_centralWidget, SLOT( globalPlaySlot()));
    42. connect( this, SIGNAL( globalStopSignal() ), m_centralWidget, SLOT( globalStopSlot()));
    43. connect( this, SIGNAL( globalASecondiSignal() ), m_centralWidget, SLOT( globalASecondiSlot()) );
    44. connect( this, SIGNAL( globalAMinutiSignal() ), m_centralWidget, SLOT( globalAMinutiSlot() ) );
    45. connect( this, SIGNAL( globalIMinutiSignal() ), m_centralWidget, SLOT( globalIMinutiSlot()) );
    46. connect( this, SIGNAL( globalISecondiSignal() ), m_centralWidget, SLOT( globalISecondiSlot()) );
    47. }
    To copy to clipboard, switch view to plain text mode 

    Here the code to run the dialog that's not translated as the rest of the application:
    Qt Code:
    1. void MainWindow::configure()
    2. {
    3. // Create the dialog at run-time
    4. ConfigDlg dialog( this );
    5. // and execute it
    6. dialog.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    The ui of the dialog is done using designer and I set every string translable ( sorry for the term ).
    Please let me know if you need more code. I can send to you the ui file if you want.

    Regards

    Quote Originally Posted by wysota View Post
    Franco... some code, please. I will not repeat myself and will only ask for enough information this one time. If you don't provide enough information yourself, I will not respond to your post. If you are lucky enough, maybe someone else will.
    Wysota I already gave to you all code last time. I don't know which code to provide.

    This is the ctor of my application:

    Qt Code:
    1. MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
    2. : QMainWindow(parent, flags),
    3. m_track1(""),
    4. m_track2(""),
    5. m_w1SourceDir(""),
    6. m_w2SourceDir(""),
    7. m_w1OutputDir(""),
    8. m_w2OutputDir(""),
    9. m_fileOneLoaded(false),
    10. m_fileTwoLoaded(false),
    11. m_trackListDlg(NULL)
    12. {
    13. setObjectName("MainWindow");
    14.  
    15. /* set window title */
    16. setWindowTitle("ECP Studio");
    17.  
    18. readSettings(); // <-- here I read settings ( also language entry )
    19.  
    20. QTranslator esTranslator;
    21. if( QString::compare(m_language,"es") == 0 )
    22. {
    23. esTranslator.load("ecpstudio_es");
    24. qApp->installTranslator(&esTranslator);
    25. }
    26.  
    27. /* create menu and status bar */
    28. createActions();
    29. createMenus();
    30. createToolBar();
    31. createStatusBar();
    32.  
    33. /* set the central widget */
    34. m_centralWidget = new CentralWidget( m_bgColor, m_wfColor, m_w1OutputDir, m_w2OutputDir, m_bgFile, m_mstep, m_sstep, m_loopInterval, this );
    35. setCentralWidget( m_centralWidget );
    36.  
    37. enableGlobalCommands( false );
    38.  
    39. connect( check, SIGNAL( stateChanged( int ) ), this, SLOT( uniqueFileChanged( int ) ) );
    40. connect( this, SIGNAL( synchSignal() ), m_centralWidget, SLOT( synchSlot()));
    41. connect( this, SIGNAL( globalPlaySignal() ), m_centralWidget, SLOT( globalPlaySlot()));
    42. connect( this, SIGNAL( globalStopSignal() ), m_centralWidget, SLOT( globalStopSlot()));
    43. connect( this, SIGNAL( globalASecondiSignal() ), m_centralWidget, SLOT( globalASecondiSlot()) );
    44. connect( this, SIGNAL( globalAMinutiSignal() ), m_centralWidget, SLOT( globalAMinutiSlot() ) );
    45. connect( this, SIGNAL( globalIMinutiSignal() ), m_centralWidget, SLOT( globalIMinutiSlot()) );
    46. connect( this, SIGNAL( globalISecondiSignal() ), m_centralWidget, SLOT( globalISecondiSlot()) );
    47. }
    To copy to clipboard, switch view to plain text mode 

    Here the code to run the dialog that's not translated as the rest of the application:
    Qt Code:
    1. void MainWindow::configure()
    2. {
    3. // Create the dialog at run-time
    4. ConfigDlg dialog( this );
    5. // and execute it
    6. dialog.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    The ui of the dialog is done using designer and I set every string translable ( sorry for the term ).
    Please let me know if you need more code. I can send to you the ui file if you want.

    Regards


    Added after 9 minutes:


    And here the ctor of the dialog ( I'm not sure it's usefull for the post )


    Qt Code:
    1. ConfigDlg::ConfigDlg( QWidget *parent )
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5. win = (MainWindow*)parent;
    6.  
    7. ui.w1SourceBtn->setIcon(QIcon(":/images/open.png"));
    8. ui.w2SourceBtn->setIcon(QIcon(":/images/open.png"));
    9. ui.w1OutputBtn->setIcon(QIcon(":/images/open.png"));
    10. ui.w2OutputBtn->setIcon(QIcon(":/images/open.png"));
    11. ui.bgSndBtn->setIcon(QIcon(":/images/open.png"));
    12.  
    13. ui.bgColorBtn->setIcon(QIcon(":/images/pickColor.png"));
    14. ui.wfColorBtn->setIcon(QIcon(":/images/pickColor.png"));
    15. ui.tlColorBtn->setIcon(QIcon(":/images/pickColor.png"));
    16. ui.mkColorBtn->setIcon(QIcon(":/images/pickColor.png"));
    17. ui.selColorBtn->setIcon(QIcon(":/images/pickColor.png"));
    18.  
    19. // read values
    20. lang = win->getLanguage();
    21. w1Src = win->getW1SrcStr();
    22. w2Src = win->getW2SrcStr();
    23. w1Dst = win->getW1DstStr();
    24. w2Dst = win->getW2DstStr();
    25. bgFile = win->getBgFile();
    26.  
    27. ui.srcW1LineEdit->setText(w1Src);
    28. ui.srcW2LineEdit->setText(w2Src);
    29. ui.dstW1LineEdit->setText(w1Dst);
    30. ui.dstW2LineEdit->setText(w2Dst);
    31. ui.bgSndLineEdit->setText(bgFile);
    32.  
    33. QColor color = win->getBgColor();
    34. p.setColor(QPalette::Window, color);
    35. ui.bgFrame->setAutoFillBackground(true);
    36. ui.bgFrame->setPalette(p);
    37. bgColor = color;
    38.  
    39. color = win->getWfColor();
    40. p.setColor(QPalette::Window, color);
    41. ui.fgFrame->setAutoFillBackground(true);
    42. ui.fgFrame->setPalette(p);
    43. wfColor = color;
    44.  
    45. color = win->getTlColor();
    46. p.setColor(QPalette::Window, color);
    47. ui.tlFrame->setAutoFillBackground(true);
    48. ui.tlFrame->setPalette(p);
    49. tlColor = color;
    50.  
    51. color = win->getMkColor();
    52. p.setColor(QPalette::Window, color);
    53. ui.mkFrame->setAutoFillBackground(true);
    54. ui.mkFrame->setPalette(p);
    55. mkColor = color;
    56.  
    57. color = win->getSlColor();
    58. p.setColor(QPalette::Window, color);
    59. ui.slFrame->setAutoFillBackground(true);
    60. ui.slFrame->setPalette(p);
    61. slColor = color;
    62.  
    63. /* add languages to combo box */
    64. ui.langComboBox->clear();
    65. ui.langComboBox->addItem("English");
    66. ui.langComboBox->addItem("Español");
    67.  
    68. uint m_sstep = win->getStepInSecondi();
    69. uint m_mstep = win->getStepInMinuti();
    70. QString s = QString::number(m_sstep);
    71. ui.secLineEdit->setAlignment(Qt::AlignRight);
    72. ui.secLineEdit->insert(s);
    73. s = QString::number(m_mstep);
    74. ui.minLineEdit->setAlignment(Qt::AlignRight);
    75. ui.minLineEdit->insert(s);
    76.  
    77.  
    78. /* valori delle ripetizioni */
    79. if( (m_loopMode = win->getLoopMode()) == "loop")
    80. ui.loopModeComboBox->addItem("loop");
    81. else
    82. ui.loopModeComboBox->addItem("once");
    83.  
    84. /* interval between loops */
    85. m_loopInterval = win->getLoopInterval();
    86. s = QString::number(m_loopInterval);
    87. ui.loopsIntervalLineEdit->setAlignment(Qt::AlignRight);
    88. ui.loopsIntervalLineEdit->insert(s);
    89.  
    90. connect( ui.okBtn, SIGNAL( released() ), this, SLOT( slotAccept() ) );
    91. connect( ui.cancelBtn, SIGNAL( released() ), this, SLOT( slotCancel() ) );
    92. connect( ui.w1SourceBtn, SIGNAL( released() ), this, SLOT( chooseW1SrcDir() ) );
    93. connect( ui.w2SourceBtn, SIGNAL( released() ), this, SLOT( chooseW2SrcDir() ) );
    94. connect( ui.w1OutputBtn, SIGNAL( released() ), this, SLOT( chooseW1OutputDir() ) );
    95. connect( ui.w2OutputBtn, SIGNAL( released() ), this, SLOT( chooseW2OutputDir() ) );
    96. connect( ui.bgSndBtn, SIGNAL( released() ), this, SLOT( chooseBgDir() ) );
    97. connect( ui.bgColorBtn, SIGNAL( released() ), this, SLOT( chooseBgColor() ) );
    98. connect( ui.wfColorBtn, SIGNAL( released() ), this, SLOT( chooseWfColor() ) );
    99. connect( ui.tlColorBtn, SIGNAL( released() ), this, SLOT( chooseTlColor() ) );
    100. connect( ui.mkColorBtn, SIGNAL( released() ), this, SLOT( chooseMkColor() ) );
    101. connect( ui.selColorBtn, SIGNAL( released() ), this, SLOT( chooseSlColor() ) );
    102. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by franco.amato; 25th October 2010 at 19:07.
    Franco Amato

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Again a problem with Translation

    And again your translator goes out of scope too early.
    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
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    Quote Originally Posted by wysota View Post
    And again your translator goes out of scope too early.
    Wysota it goes out of scope? So Qt translate the dialogs in the same moment of their creation? Do I well understood?
    Franco Amato

  9. #9
    Join Date
    Oct 2010
    Location
    Cracow,Bielsko-Biała/Polska
    Posts
    15
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: Again a problem with Translation

    Add member to class MainWindow, like
    Qt Code:
    1. QTranslator m_translator;
    To copy to clipboard, switch view to plain text mode 
    In CTOR changes like below:

    Qt Code:
    1. ....
    2. readSettings(); // <-- here I read settings ( also language entry )
    3. if( QString::compare(m_language,"es") == 0 )
    4. {
    5. m_translator.load("ecpstudio_es");
    6. qApp->installTranslator(&esTranslator);
    7. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    Quote Originally Posted by Leszek View Post
    Add member to class MainWindow, like
    Qt Code:
    1. QTranslator m_translator;
    To copy to clipboard, switch view to plain text mode 
    In CTOR changes like below:

    Qt Code:
    1. ....
    2. readSettings(); // <-- here I read settings ( also language entry )
    3. if( QString::compare(m_language,"es") == 0 )
    4. {
    5. m_translator.load("ecpstudio_es");
    6. qApp->installTranslator(&esTranslator);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Yes this is what I did after the reply of wysota thank you.
    It works.

    Regards
    Franco Amato

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Again a problem with Translation

    Quote Originally Posted by franco.amato View Post
    Wysota it goes out of scope?
    Doesn't it?

    So Qt translate the dialogs in the same moment of their creation? Do I well understood?
    Qt translates dialogs when results of appropriate tr() calls are assigned to widgets' visible text. There is no magic here anywhere.
    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.


  12. The following user says thank you to wysota for this useful post:

    franco.amato (25th October 2010)

  13. #12
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Again a problem with Translation

    Many thanks wysota
    Franco Amato

Similar Threads

  1. Translation problem while scaling an object
    By qlands in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2010, 12:04
  2. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 11:01
  3. QFileDialog/ QMessageBox's Button Translation problem
    By santosh.kumar in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2009, 07:07
  4. problem with Translation
    By #andi# in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 15:14
  5. Problem with dynamic translation
    By keo in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 10:36

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
  •  
Qt is a trademark of The Qt Company.