Hi to all,
I would know how set the settings of my application to manage translation.
For example if I choose english, when I restart the application I would have english as language.
Best Regards
Hi to all,
I would know how set the settings of my application to manage translation.
For example if I choose english, when I restart the application I would have english as language.
Best Regards
Franco Amato
Qt Code:
{ Q_UNUSED(ce); writeSettings(); }To copy to clipboard, switch view to plain text mode
and
Qt Code:
void MainWindow::writeSettings() { /* language group */ settings.beginGroup("language"); settings.setValue("lang", m_language); settings.endGroup(); /* paths group */ settings.beginGroup("paths"); settings.setValue("w1_source", m_w1SourceDir); settings.setValue("w2_source", m_w2SourceDir); settings.setValue("w1_output", m_w1OutputDir); settings.setValue("w2_output", m_w2OutputDir); settings.endGroup(); /* colors group */ settings.beginGroup("colors"); settings.setValue("background", m_bgColor); settings.setValue("waveform", m_wfColor); settings.setValue("timeline", m_tlColor); settings.setValue("markers" , m_mkColor); settings.setValue("selection", m_slColor); settings.endGroup(); /* background */ settings.beginGroup("background"); settings.setValue("file", m_bgFile); settings.setValue("loop_interval", m_loopInterval); settings.setValue("loop_mode", m_loopMode); settings.endGroup(); /* steps */ settings.beginGroup("steps"); settings.setValue("sec", m_sstep); settings.setValue("min", m_mstep); settings.endGroup(); }To copy to clipboard, switch view to plain text mode
Franco Amato
I'm not sure that storing the settings in the current working directory is a good idea. Anyway, how does the reading part look like? Also does the configuration file get created? Does it have proper contents?
Franco Amato
Either store the settings in a "well known location" like the user's home directory or use the application binary directory or let Qt choose the proper location.
Please provide enough information for us to see how you try to apply the language change using your settings. I'm tired of having to drag every piece of information out of you. If you want help, provide enough information to see where the problem might be. And do it always, not only in this thread, you have already over 400 posts on this forum, for God's sake! Every thread of yours is at least 5 times longer than questions asked by others. If you have problem with specifying your problem, maybe you should take a look at how others do it.It works for all settings except for the language
and you read your settings file how?
How can I let Qt decide where? Can I speak with Qt and ask where it would store the configuration file?
Please wysota give a look at your replies. They are also written with Morse code, and I always have to ask 'please can you be more clear' or I always have to beg for 2 lines of clarifing code of example as in the above statement ( let Qt decide where ).Please provide enough information for us to see how you try to apply the language change using your settings. I'm tired of having to drag every piece of information out of you. If you want help, provide enough information to see where the problem might be. And do it always, not only in this thread, you have already over 400 posts on this forum, for God's sake! Every thread of yours is at least 5 times longer than questions asked by others. If you have problem with specifying your problem, maybe you should take a look at how others do it.
I'm sure I'm not the only person thinking that.
I stopped to post questions in the 'Programming' sections hoping to have more clear replies (to improve my Qt level) but is not so.
Franco Amato
This is my routine to read settings:
Qt Code:
void MainWindow::readSettings() { /* language group */ settings.beginGroup("language"); m_language = settings.value("lang", "en").toString(); settings.endGroup(); /* paths group */ settings.beginGroup("paths"); m_w1SourceDir = settings.value("w1_source", "C:").toString(); m_w2SourceDir = settings.value("w2_source", "C:").toString(); m_w1OutputDir = settings.value("w1_output", "C:").toString(); m_w2OutputDir = settings.value("w2_output", "C:").toString(); settings.endGroup(); /* background file */ settings.beginGroup("background"); m_bgFile = settings.value("file", "./audio de fondo/Grabacion_marca de agua_cruz report - MONO.mp3").toString(); m_loopMode = settings.value("loop_mode", "loop").toString(); m_loopInterval = settings.value("loop_interval", 5).toInt(); settings.endGroup(); /* steps */ settings.beginGroup("steps"); m_sstep = settings.value("sec", 1).toInt(); m_mstep = settings.value("min", 1).toInt(); settings.endGroup(); /* colors group */ settings.beginGroup("colors"); QVariant colVariant = defColor; m_bgColor = settings.value( "background", colVariant ).value<QColor>(); m_wfColor = settings.value( "waveform", Qt::darkBlue ).value<QColor>(); m_tlColor = settings.value( "timeline", Qt::darkRed ).value<QColor>(); m_mkColor = settings.value( "markers", Qt::yellow ).value<QColor>(); m_slColor = settings.value( "selection", Qt::red ).value<QColor>(); settings.endGroup(); }To copy to clipboard, switch view to plain text mode
I installed 2 translation files in the main.cpp so:
Qt Code:
QTranslator enTranslator; enTranslator.load( "ecpstudio_en"); app.installTranslator( &enTranslator ); QTranslator esTranslator; esTranslator.load( "ecpstudio_es"); app.installTranslator( &esTranslator );To copy to clipboard, switch view to plain text mode
then I perform a test on the m_language variable ( after read the configuration file )
Qt Code:
// here I would do effective the english translation file else // here I would do effective the spanish translation fileTo copy to clipboard, switch view to plain text mode
Last edited by franco.amato; 21st October 2010 at 22:53.
Franco Amato
Why multiple installTranslator? Just call it once depending on which language you want and use QObject::tr() for translations.
Please - for once - go and read the documentation provided with Qt on internationalization. Qt's system isn't the best I've seen, but it works and it's relatively simple. It does, however, require the person using it to make the small effort required to learn how it is used. There are extensive tutorials, documentation and sample code that describe all of the small number of details it possesses.
If you pass a file path using a constructor then the logical assumption would be to look at other constructors.
If you want to "ask Qt" about something, you can read the reference manual.Can I speak with Qt and ask where it would store the configuration file?
I'm expecting you to posses some knowledge. I won't tell you how to turn on your computer or login to your account. I expect you to know that. I also expect you to know how to do some basic things in Qt and if you are lazy enough not to find information about it yourself then I expect you to ask specific questions about problems you have. I expect to be talking not to a brainless brick but to an intelligent human being.Please wysota give a look at your replies. They are also written with Morse code, and I always have to ask 'please can you be more clear' or I always have to beg for 2 lines of clarifing code of example as in the above statement ( let Qt decide where ).
You won't improve yourself by asking questions. Learn by doing and trying to solve your problems first before you go somewhere and ask for help.I stopped to post questions in the 'Programming' sections hoping to have more clear replies (to improve my Qt level) but is not so.
I already did.
I modified my code removing the QTranslation instance from main.cpp and adding it to my MainWindow.cpp ctor so:
Qt Code:
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"); //setMinimumSize(800, 400); /* creo il menu e la status bar */ createActions(); createMenus(); createToolBar(); createStatusBar(); readSettings(); // here I fill the m_language variable { QTranslator esTranslator; esTranslator.load("ecpstudio_es"); } /* 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()) ); }To copy to clipboard, switch view to plain text mode
and it has no effect, language is always english ( instead of spanish as it should be - because I set 'es' in the configuration file ).
Regards
Last edited by franco.amato; 22nd October 2010 at 00:03.
Franco Amato
After 18 posts we have the full source code to answer your question. Great! But still we are missing some debug informations:And you might want to move the translator installation to the top, since you don't support dynamic language switching. So all actions and menus wont get retranslated. But that all stands in the documentation as well.
- Is the if block entered?
- Is load really returns true?
Franco, tell me, what is the value of "x" in the place marked with /* ??? */ in the following code? Could you explain why? As a hint - you can write a little program to test it:
Qt Code:
if(true){ int x = 7; } /* ??? */To copy to clipboard, switch view to plain text mode
Bookmarks