PDA

View Full Version : how to change language of text edit or line edit using change of combobox item



thomasjoy
14th May 2007, 13:25
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

jpn
14th May 2007, 13:48
Maybe this helps: QtCentreWiki - Dynamic translation (http://wiki.qtcentre.org/index.php?title=Dynamic_translation) (notice that there's also an example there).

thomasjoy
14th May 2007, 14:19
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


.

jpn
14th May 2007, 14:22
Please use [ code ] -tags around code blocks to make the readable. Notice the "#"-button in the wysiwyg-editor.

thomasjoy
14th May 2007, 14:42
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

jpn
14th May 2007, 14:48
What does the line edit and/or the text edit contain? Are they read-only or is user allowed to enter basically anything?

wysota
14th May 2007, 14:49
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.

thomasjoy
15th May 2007, 07:10
it means to say we cannot change user given text on run time into another than english language....is it???

wysota
15th May 2007, 10:21
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.