Results 1 to 9 of 9

Thread: how to change language of text edit or line edit using change of combobox item

  1. #1
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question 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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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).
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question 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


    .

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    thomasjoy (14th May 2007)

  6. #5
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question 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

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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?
    J-P Nurmi

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

    Default 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.

  9. #8
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question 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???

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

    Default 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.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.