how to change language of text edit or line edit using change of combobox item
hi experts
i'm working on Mac OS 10.4 and using qt4.2 for developing application
can u please tell me how can i change the text of line edit or text edit in after selecting a new language in my code which r included in my application folder
u see my .pro file and .qrc file
.qrc file is:
<RCC version="1.0">
<qresource>
<file>translations/langChange_ar.qm</file>
<file>translations/langChange_cs.qm</file>
<file>translations/langChange_de.qm</file>
<file>translations/langChange_el.qm</file>
</qresource>
</RCC>
.pro file is
TEMPLATE = app
TARGET =
DEPENDPATH += . translations
INCLUDEPATH += .
# Input
HEADERS += langChange.h
FORMS += langChange.ui
SOURCES += langChange.cpp main.cpp
RESOURCES += langchange.qrc
TRANSLATIONS += translations/langChange_ar.ts \
translations/langChange_cs.ts \
translations/langChange_de.ts \
translations/langChange_el.ts
now can u please do tell me where is the problem going on
code is:
langChange::langChange(QWidget *parent): QDialog(parent)
{
setupUi(this);
qmFiles = namesQmFiles();
languageChanged();
connect(comboBox,SIGNAL(activated(QString )), this,SLOT(changed(QString )));
}
void langChange :: languageChanged()
{
for (int i = 0; i < qmFiles.size(); i++)
{
comboBox->insertItem(0,languageName(qmFiles[i]),QVariant());
}
}
void langChange :: changed(QString str)
{
str=textEdit->toPlainText ();
//QMessageBox::information(0,"!!",languageName(str)) ;
//WHAT TO DO
}
/*WHEN I USE QMESSAGEBOX TO GET TRANSLATED STRING IT RETURNS NOTHING
QString langChange::languageName(const QString &qmFile)
{
QTranslator translator;
translator.load(qmFile);
//qApp->installTranslator(&translator);
return translator.translate("MainWindow", "English");
}
QStringList langChange::namesQmFiles()
{
QDir dir("/test/translations");
QString strFileName = "";
QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files,QDir::Name);
QMutableStringListIterator i(fileNames);
while (i.hasNext())
{
i.next();
i.setValue(dir.filePath(i.value()));
}
return fileNames;
}
PLEASE DO TELL ME WHERE THE PROBLEM IS OCCURING TO GET TRANSLATED STRING IN ANY OTHER LANGUAGE AS 4 .qm FILES ARE LOADED IN COMBOBOX
WHAT TO DO WITH CODE OR WHAT WILL BE THE SIGNAL SLOT ..IS THERE ANY PROBLEM IN SIGNAL SLOT OR WHAT TYPE...I AM NOT GETTING WHY STRING NOT TRANSLATED IF LANGUAGE NAMES ARE LOADED IN COMBOBOX IN DIFFRENT LANGUAGES
THANKS IN ADVANCE
Re: how to change language of text edit or line edit using change of combobox item
Maybe this helps: QtCentreWiki - Dynamic translation (notice that there's also an example there).
Re: how to change language of text edit or line edit using change of combobox item
thanks for replying...
in your's example output is on already given text....but i am changing the text on run time
using text edit or line edit and selecting my language from combo box
so can you please suggest me the code example for my code
what changes i have to do in my code
required output is user enter the text in textEdit
i have the multiple languages list in combobox
user change the language from combobox as soon as user change the combobox's language string the textEdit's field or lineEdit's field language should also changed in that particular language which ever selected by user from combobox.
i mean i wanna know what i have to do here from above code
void langChange :: changed(QString str)
{
str=lineEdit->text();
QMessageBox::information(0,"!!",languageName(str)) ;
//WHT TO DO
}
thanks in advance
.
Re: how to change language of text edit or line edit using change of combobox item
Please use [ code ] -tags around code blocks to make the readable. Notice the "#"-button in the wysiwyg-editor.
Re: how to change language of text edit or line edit using change of combobox item
thanks for replying...
in your's example output is on already given text....but i am changing the text on run time
using text edit or line edit and selecting my language from combo box
so can you please suggest me the code example for my code
what changes i have to do in my code
required output is user enter the text in textEdit
i have the multiple languages list in combobox
user change the language from combobox as soon as user change the combobox's language string the textEdit's field or lineEdit's field language should also changed in that particular language which ever selected by user from combobox.
i mean i wanna know what i have to do here from above code
Quote:
void langChange :: changed(QString str)
{
str=lineEdit->text();
QMessageBox::information(0,"!!",languageName(str)) ;
//WHT TO DO
}
thanks in advance
Re: how to change language of text edit or line edit using change of combobox item
What does the line edit and/or the text edit contain? Are they read-only or is user allowed to enter basically anything?
Re: how to change language of text edit or line edit using change of combobox item
You can't translate dynamic text on the fly. It just wouldn't make sense. If you need it, do the translation manually upon QEvent::LanguageChange event.
Re: how to change language of text edit or line edit using change of combobox item
it means to say we cannot change user given text on run time into another than english language....is it???
Re: how to change language of text edit or line edit using change of combobox item
It means Qt translation tools are not a general use dictionary and don't support such a thing (and I've never heard of a i18n mechanism that would support it). You'd have to practically implement a complete context-detecting dictionary engine for that. The translation in Qt (or in gettext) concers static strings with optional arguments (that have to be translated separately), not free written text.