PDA

View Full Version : Again a problem with Translation



franco.amato
25th October 2010, 18:42
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

genjix
25th October 2010, 19:15
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 :p

franco.amato
25th October 2010, 19:33
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 5399 explaining my problem.
This is the better way I can explain my problem.
Regards

wysota
25th October 2010, 19:45
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.

Leszek
25th October 2010, 19:47
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...

franco.amato
25th October 2010, 20:07
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:


MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow(parent, flags),
m_track1(""),
m_track2(""),
m_w1SourceDir(""),
m_w2SourceDir(""),
m_w1OutputDir(""),
m_w2OutputDir(""),
m_fileOneLoaded(false),
m_fileTwoLoaded(false),
m_trackListDlg(NULL)
{
setObjectName("MainWindow");

/* set window title */
setWindowTitle("ECP Studio");

readSettings(); // <-- here I read settings ( also language entry )

QTranslator esTranslator;
if( QString::compare(m_language,"es") == 0 )
{
esTranslator.load("ecpstudio_es");
qApp->installTranslator(&esTranslator);
}

/* create menu and status bar */
createActions();
createMenus();
createToolBar();
createStatusBar();

/* set the central widget */
m_centralWidget = new CentralWidget( m_bgColor, m_wfColor, m_w1OutputDir, m_w2OutputDir, m_bgFile, m_mstep, m_sstep, m_loopInterval, this );
setCentralWidget( m_centralWidget );

enableGlobalCommands( false );

connect( check, SIGNAL( stateChanged( int ) ), this, SLOT( uniqueFileChanged( int ) ) );
connect( this, SIGNAL( synchSignal() ), m_centralWidget, SLOT( synchSlot()));
connect( this, SIGNAL( globalPlaySignal() ), m_centralWidget, SLOT( globalPlaySlot()));
connect( this, SIGNAL( globalStopSignal() ), m_centralWidget, SLOT( globalStopSlot()));
connect( this, SIGNAL( globalASecondiSignal() ), m_centralWidget, SLOT( globalASecondiSlot()) );
connect( this, SIGNAL( globalAMinutiSignal() ), m_centralWidget, SLOT( globalAMinutiSlot() ) );
connect( this, SIGNAL( globalIMinutiSignal() ), m_centralWidget, SLOT( globalIMinutiSlot()) );
connect( this, SIGNAL( globalISecondiSignal() ), m_centralWidget, SLOT( globalISecondiSlot()) );
}

Here the code to run the dialog that's not translated as the rest of the application:

void MainWindow::configure()
{
// Create the dialog at run-time
ConfigDlg dialog( this );
// and execute it
dialog.exec();
}

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


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:


MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow(parent, flags),
m_track1(""),
m_track2(""),
m_w1SourceDir(""),
m_w2SourceDir(""),
m_w1OutputDir(""),
m_w2OutputDir(""),
m_fileOneLoaded(false),
m_fileTwoLoaded(false),
m_trackListDlg(NULL)
{
setObjectName("MainWindow");

/* set window title */
setWindowTitle("ECP Studio");

readSettings(); // <-- here I read settings ( also language entry )

QTranslator esTranslator;
if( QString::compare(m_language,"es") == 0 )
{
esTranslator.load("ecpstudio_es");
qApp->installTranslator(&esTranslator);
}

/* create menu and status bar */
createActions();
createMenus();
createToolBar();
createStatusBar();

/* set the central widget */
m_centralWidget = new CentralWidget( m_bgColor, m_wfColor, m_w1OutputDir, m_w2OutputDir, m_bgFile, m_mstep, m_sstep, m_loopInterval, this );
setCentralWidget( m_centralWidget );

enableGlobalCommands( false );

connect( check, SIGNAL( stateChanged( int ) ), this, SLOT( uniqueFileChanged( int ) ) );
connect( this, SIGNAL( synchSignal() ), m_centralWidget, SLOT( synchSlot()));
connect( this, SIGNAL( globalPlaySignal() ), m_centralWidget, SLOT( globalPlaySlot()));
connect( this, SIGNAL( globalStopSignal() ), m_centralWidget, SLOT( globalStopSlot()));
connect( this, SIGNAL( globalASecondiSignal() ), m_centralWidget, SLOT( globalASecondiSlot()) );
connect( this, SIGNAL( globalAMinutiSignal() ), m_centralWidget, SLOT( globalAMinutiSlot() ) );
connect( this, SIGNAL( globalIMinutiSignal() ), m_centralWidget, SLOT( globalIMinutiSlot()) );
connect( this, SIGNAL( globalISecondiSignal() ), m_centralWidget, SLOT( globalISecondiSlot()) );
}

Here the code to run the dialog that's not translated as the rest of the application:

void MainWindow::configure()
{
// Create the dialog at run-time
ConfigDlg dialog( this );
// and execute it
dialog.exec();
}

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 )



ConfigDlg::ConfigDlg( QWidget *parent )
: QDialog(parent)
{
ui.setupUi(this);
win = (MainWindow*)parent;

ui.w1SourceBtn->setIcon(QIcon(":/images/open.png"));
ui.w2SourceBtn->setIcon(QIcon(":/images/open.png"));
ui.w1OutputBtn->setIcon(QIcon(":/images/open.png"));
ui.w2OutputBtn->setIcon(QIcon(":/images/open.png"));
ui.bgSndBtn->setIcon(QIcon(":/images/open.png"));

ui.bgColorBtn->setIcon(QIcon(":/images/pickColor.png"));
ui.wfColorBtn->setIcon(QIcon(":/images/pickColor.png"));
ui.tlColorBtn->setIcon(QIcon(":/images/pickColor.png"));
ui.mkColorBtn->setIcon(QIcon(":/images/pickColor.png"));
ui.selColorBtn->setIcon(QIcon(":/images/pickColor.png"));

// read values
lang = win->getLanguage();
w1Src = win->getW1SrcStr();
w2Src = win->getW2SrcStr();
w1Dst = win->getW1DstStr();
w2Dst = win->getW2DstStr();
bgFile = win->getBgFile();

ui.srcW1LineEdit->setText(w1Src);
ui.srcW2LineEdit->setText(w2Src);
ui.dstW1LineEdit->setText(w1Dst);
ui.dstW2LineEdit->setText(w2Dst);
ui.bgSndLineEdit->setText(bgFile);

QPalette p;
QColor color = win->getBgColor();
p.setColor(QPalette::Window, color);
ui.bgFrame->setAutoFillBackground(true);
ui.bgFrame->setPalette(p);
bgColor = color;

color = win->getWfColor();
p.setColor(QPalette::Window, color);
ui.fgFrame->setAutoFillBackground(true);
ui.fgFrame->setPalette(p);
wfColor = color;

color = win->getTlColor();
p.setColor(QPalette::Window, color);
ui.tlFrame->setAutoFillBackground(true);
ui.tlFrame->setPalette(p);
tlColor = color;

color = win->getMkColor();
p.setColor(QPalette::Window, color);
ui.mkFrame->setAutoFillBackground(true);
ui.mkFrame->setPalette(p);
mkColor = color;

color = win->getSlColor();
p.setColor(QPalette::Window, color);
ui.slFrame->setAutoFillBackground(true);
ui.slFrame->setPalette(p);
slColor = color;

/* add languages to combo box */
ui.langComboBox->clear();
ui.langComboBox->addItem("English");
ui.langComboBox->addItem("Español");

uint m_sstep = win->getStepInSecondi();
uint m_mstep = win->getStepInMinuti();
QString s = QString::number(m_sstep);
ui.secLineEdit->setAlignment(Qt::AlignRight);
ui.secLineEdit->insert(s);
s = QString::number(m_mstep);
ui.minLineEdit->setAlignment(Qt::AlignRight);
ui.minLineEdit->insert(s);


/* valori delle ripetizioni */
if( (m_loopMode = win->getLoopMode()) == "loop")
ui.loopModeComboBox->addItem("loop");
else
ui.loopModeComboBox->addItem("once");

/* interval between loops */
m_loopInterval = win->getLoopInterval();
s = QString::number(m_loopInterval);
ui.loopsIntervalLineEdit->setAlignment(Qt::AlignRight);
ui.loopsIntervalLineEdit->insert(s);

connect( ui.okBtn, SIGNAL( released() ), this, SLOT( slotAccept() ) );
connect( ui.cancelBtn, SIGNAL( released() ), this, SLOT( slotCancel() ) );
connect( ui.w1SourceBtn, SIGNAL( released() ), this, SLOT( chooseW1SrcDir() ) );
connect( ui.w2SourceBtn, SIGNAL( released() ), this, SLOT( chooseW2SrcDir() ) );
connect( ui.w1OutputBtn, SIGNAL( released() ), this, SLOT( chooseW1OutputDir() ) );
connect( ui.w2OutputBtn, SIGNAL( released() ), this, SLOT( chooseW2OutputDir() ) );
connect( ui.bgSndBtn, SIGNAL( released() ), this, SLOT( chooseBgDir() ) );
connect( ui.bgColorBtn, SIGNAL( released() ), this, SLOT( chooseBgColor() ) );
connect( ui.wfColorBtn, SIGNAL( released() ), this, SLOT( chooseWfColor() ) );
connect( ui.tlColorBtn, SIGNAL( released() ), this, SLOT( chooseTlColor() ) );
connect( ui.mkColorBtn, SIGNAL( released() ), this, SLOT( chooseMkColor() ) );
connect( ui.selColorBtn, SIGNAL( released() ), this, SLOT( chooseSlColor() ) );
}

wysota
25th October 2010, 20:08
And again your translator goes out of scope too early.

franco.amato
25th October 2010, 20:15
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?

Leszek
25th October 2010, 20:18
Add member to class MainWindow, like
QTranslator m_translator;
In CTOR changes like below:


....
readSettings(); // <-- here I read settings ( also language entry )
if( QString::compare(m_language,"es") == 0 )
{
m_translator.load("ecpstudio_es");
qApp->installTranslator(&esTranslator);
}

franco.amato
25th October 2010, 20:22
Add member to class MainWindow, like
QTranslator m_translator;
In CTOR changes like below:


....
readSettings(); // <-- here I read settings ( also language entry )
if( QString::compare(m_language,"es") == 0 )
{
m_translator.load("ecpstudio_es");
qApp->installTranslator(&esTranslator);
}


Yes this is what I did after the reply of wysota thank you.
It works.

Regards

wysota
25th October 2010, 20:23
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.

franco.amato
25th October 2010, 20:26
Many thanks wysota