Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT Translation - Multi Language Support
Forum Updated to NodeBB v4.3 + New Features

QT Translation - Multi Language Support

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 5.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janga
    wrote on last edited by
    #1

    Hi All,

    I have written a code in QT where it creates four push buttons and then on clicking one of the Pushbutton button by name "Up" . All the names of buttons should be changed is my intention. I have generated the *.ts file and *.qm file using lupdate and lrelease. For your reference iam using QT creator.

    But the names are not getting translated.

    mainwindow.cpp code is as below

    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    upButton = new QPushButton(tr("&Up"),this);
    downButton = new QPushButton(tr("&Down"),this);
    leftButton = new QPushButton(tr("&Left"),this);
    rightButton = new QPushButton(tr("&Right"),this);

    upButton->setGeometry(40,40,40,40);
    downButton->setGeometry(80,40,40,40);
    rightButton->setGeometry(80,80,40,40);
    leftButton->setGeometry(40,100,40,40);

    connect ( upButton,SIGNAL( clicked() ),this,SLOT( tion() ) );

    }

    void MainWindow::tion()

    {
    QTranslator qtTranslator;

    if (qtTranslator.load(QString("C:\Users\janga\Desktop\Label\trans\sample.qm")))
    {
    QMessageBox abc;
    abc.setText("abc");
    abc.exec();
    }
    QApplication::installTranslator(&qtTranslator);

    ui->retranslateUi(this);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    main.cpp code is as below

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

    MainWindow w;
    
    w.show();
    
    return a.exec();
    

    }
    @

    sample.ts file as below

    @
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.0">
    <context>
    <name>MainWindow</name>
    <message>
    <location filename="mainwindow.ui" line="14"/>
    <source>MainWindow</source>
    <translation type="unfinished"></translation>
    </message>
    <message>
    <location filename="mainwindow.cpp" line="14"/>
    <source>&Up</source>
    <translation type="unfinished"></translation>
    </message>
    <message>
    <location filename="mainwindow.cpp" line="15"/>
    <source>&Down</source>
    <translation type="unfinished"></translation>
    </message>
    <message>
    <location filename="mainwindow.cpp" line="16"/>
    <source>&Left</source>
    <translation type="unfinished"></translation>
    </message>
    <message>
    <location filename="mainwindow.cpp" line="17"/>
    <source>&Right</source>
    <translation type="unfinished"></translation>
    </message>
    </context>
    </TS>
    @

    Can you people please help me out.

    [edit: Added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      hi and welcome to devnet.

      i cann't see in which language you want to convert your application?

      Show me your .pro file

      *Note : please add @ tags before and after your code.

      Be Cute

      1 Reply Last reply
      0
      • J Offline
        J Offline
        janga
        wrote on last edited by
        #3

        Hi my pro file

        QT += core gui

        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

        TARGET = trans
        TEMPLATE = app

        SOURCES += main.cpp
        mainwindow.cpp

        HEADERS += mainwindow.h

        FORMS += mainwindow.ui

        TRANSLATIONS = sample.ts

        follwing is my ts file with respective button changes translation

        <?xml version="1.0" encoding="utf-8"?>
        <!DOCTYPE TS>
        <TS version="2.0">
        <context>
        <name>MainWindow</name>
        <message>
        <location filename="mainwindow.ui" line="14"/>
        <source>MainWindow</source>
        <translation type="unfinished"></translation>
        </message>
        <message>
        <location filename="mainwindow.cpp" line="14"/>
        <source>&Up</source>
        <translation type="unfinished"></translation>
        </message>
        <message>
        <location filename="mainwindow.cpp" line="15"/>
        <source>&Down</source>
        <translation type="unfinished">ccc</translation>
        </message>
        <message>
        <location filename="mainwindow.cpp" line="16"/>
        <source>&Left</source>
        <translation type="unfinished">bbbb</translation>
        </message>
        <message>
        <location filename="mainwindow.cpp" line="17"/>
        <source>&Right</source>
        <translation type="unfinished">aaa</translation>
        </message>
        </context>
        </TS>

        iam new to Qtranslation can you help me out

        1 Reply Last reply
        0
        • J Offline
          J Offline
          janga
          wrote on last edited by
          #4

          My main aim is when i press one of the button language other buttons should change

          1 Reply Last reply
          0
          • J Offline
            J Offline
            janga
            wrote on last edited by
            #5

            Its urgent please or else please provide me any code

            1 Reply Last reply
            0
            • IamSumitI Offline
              IamSumitI Offline
              IamSumit
              wrote on last edited by
              #6

              Hi.
              -i saw there are lot of insufficient code .-
              -1)in .pro file-
              -Problem : -TRANSLATIONS = sample.ts-

              -2)in xml (*.ts)-
              -Problem : -<TS version=“2.0”>-

              "Link : ":http://doc.gnu-darwin.org/linguist/tt1.html

              (Edited@IamSumit)

              hope it helps

              Be Cute

              1 Reply Last reply
              0
              • J Offline
                J Offline
                janga
                wrote on last edited by
                #7

                Hi i have changed the ts file as below still iam not able too see any translation

                <?xml version="1.0" encoding="utf-8"?>
                <!DOCTYPE TS><TS>
                <context>
                <name>MainWindow</name>
                <message>
                <location filename="mainwindow.ui" line="14"/>
                <source>MainWindow</source>
                <translation></translation>
                </message>
                <message>
                <location filename="mainwindow.cpp" line="14"/>
                <source>&Up</source>
                <translation></translation>
                </message>
                <message>
                <location filename="mainwindow.cpp" line="15"/>
                <source>&Down</source>
                <translation>ccc</translation>
                </message>
                <message>
                <location filename="mainwindow.cpp" line="16"/>
                <source>&Left</source>
                <translation>bbbb</translation>
                </message>
                <message>
                <location filename="mainwindow.cpp" line="17"/>
                <source>&Right</source>
                <translation>aaa</translation>
                </message>
                </context>
                </TS>

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi and welcome to devnet,

                  What you have to write in order to do dynamic translation can be found in the "Internationalization with Qt" chapter of Qt's documentation. More precisely under "Dynamic Translation"

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • IamSumitI Offline
                    IamSumitI Offline
                    IamSumit
                    wrote on last edited by
                    #9

                    hi
                    -show me your modified .pro file code.-

                    (Edited@IamSumit))

                    Be Cute

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      It's not a pro file problem. The code from janga is not written to support dynamic translation.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        janga
                        wrote on last edited by
                        #11

                        Can you please help me out for dynamic translation and or with any sample code

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          janga
                          wrote on last edited by
                          #12

                          THis is my pro file

                          QT += core gui

                          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                          TARGET = trans
                          TEMPLATE = app

                          SOURCES += main.cpp
                          mainwindow.cpp

                          HEADERS += mainwindow.h

                          FORMS += mainwindow.ui

                          TRANSLATIONS = sample.ts

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            janga
                            wrote on last edited by
                            #13

                            Its Very Urgent Can you people send me the code snippet for me or please suggest me any changes in my code

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Go to the documentation chapter I indicated, there's everything you need there including code.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                janga
                                wrote on last edited by
                                #15

                                Thanks for the support. I got it

                                1 Reply Last reply
                                0
                                • J Offline
                                  J Offline
                                  janga
                                  wrote on last edited by
                                  #16

                                  i have one more question
                                  I am going to use eclipse IDE for QT GUI development.

                                  Eclipse doesnt have QT plugins. Then how to use lupdate and lrelease.

                                  Can i know how to use lupdate and lrelease manually.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved