How to translate a string into hindi



  • hello all..
    i am new to qt. and i want to convert the english text to hindi. But i couldnot find any devnagari family supported in Qfont..
    I could convert text into various fonts like times new roman, sans serif etc, but not in hindi..

    @ QFont f("Dev Kruti 010",12,QFont::Bold);
    QFont g("Times New Roman",12,QFont::Bold);
    ui->hindiEdit->setFont(f);
    ui->englishEdit->setFont(g);@

    But i could get hindi font in hindiEdit, rather some english family font is displayed..
    can anyone help me in this?



  • I also tried using Qtextcodec but could not succed in this...

    @QString encoded_string = "blah blah"; // Some ISO 8859-5 encoded text.
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("U-0973"));
    QByteArray string = QTextCodec::fromUnicode("ram");//QTextCodec::fromUnicode("encoded_string");
    ui->hindiEdit->setText(string);@

    here error is generated like this one:
    @/home/hello50/mainwindow.cpp:26: error: cannot call member function 'QByteArray QTextCodec::fromUnicode(const QString&) const' without object@

    I could not identify the error in this.. and hence unable to resolve the error.. can any one help me ?



  • hello @arkenold.. i too stuck here only can you explain if you have solved it please....(basically i want to display kannada language)





  • Thanks for your reply, in Qt 4.8.1 i got it done by all languages but in Qt 5.0.2 its somewhat bit hectic to do.. so trying out it..
    Thanks



  • you can aslo see qtranslator.may be below code helps you.

    @#include <iostream.h>
    #include <qapplication.h>
    #include <qtranslator.h>
    #include <qlabel.h>
    #include <qpushbutton.h>
    #include <qlayout.h>
    #include <qmultilineedit.h>
    #include <qmenubar.h>
    #include <qpopupmenu.h>

    class ExampleWidget : public QWidget
    {
    public:
    ExampleWidget( QWidget *parent = 0, const char *name = 0 );
    ~ExampleWidget();
    private:
    };

    ExampleWidget::ExampleWidget( QWidget *parent, const char *name )
    : QWidget( parent, name )
    {

    QBoxLayout *topLayout = new QVBoxLayout( this, 5 );

    QMenuBar menubar = new QMenuBar( this );
    menubar->setSeparator( QMenuBar::InWindowsStyle );
    QPopupMenu
    popup;
    popup = new QPopupMenu( this );
    popup->insertItem( tr("&Quit"), qApp, SLOT(quit()) );
    menubar->insertItem( tr("&File"), popup );

    topLayout->setMenuBar( menubar );

    QBoxLayout *buttons = new QHBoxLayout( topLayout);

    int i;
    for ( i = 1; i <= 4; i++ ) {

    QPushButton* but = new QPushButton( this );
    QString s = tr("Button %1").arg(i);
    but->setText( s );

    buttons->addWidget( but, 10 );
    }

    QMultiLineEdit *bigWidget = new QMultiLineEdit( this );
    bigWidget->setText( tr("This widget will get all the remaining space") );
    bigWidget->setFrameStyle( QFrame::Panel | QFrame::Plain );

    topLayout->addWidget( bigWidget);

    QLabel* sb = new QLabel( this );
    sb->setText(tr("Let's pretend this is a status bar"));
    sb->setFrameStyle( QFrame::Panel | QFrame::Sunken );
    sb->setFixedHeight( sb->sizeHint().height() );
    sb->setAlignment( AlignVCenter | AlignLeft );

    topLayout->addWidget( sb );

    topLayout->activate();
    }

    ExampleWidget::~ExampleWidget()
    {
    }

    int main( int argc, char **argv )
    {
    QApplication a( argc, argv );

    if(argc < 2) {
    cout << "Usage: ./i18n -[gb|big5]\n";
    exit(1);
    }

    a.setFont(QFont("Times", 16, QFont::Normal));

    QTranslator *translator = new QTranslator(0);
    if(!strcmp(argv[1], "-gb")){

    translator->load("i18n_gb.qm", ".");
    } else if(!strcmp(argv[1], "-big5")){

    translator->load("i18n_big5.qm", ".");
    }
    a.installTranslator(translator);

    ExampleWidget f;
    a.setMainWidget(&f);
    f.show();

    return a.exec();
    }
    @



  • Thanks for your reply..
    actually my UI is done in QML file.. and in and i generated the .ts files and released the .qm files also but still it displaying the boxes,,, But the same code working for QT 4.8.1. not for 5.0.1



  • I have solved it three weeks back it has been done dynamically too..

    thanks



  • vishu can u share your example I am searching for the same application if yes mail me at--: praveen0991kr@gmail.com


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.