Results 1 to 2 of 2

Thread: Problrm with Qt translation

  1. #1
    Join Date
    Mar 2010
    Posts
    69
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Problrm with Qt translation

    Hello Everyone,
    I am developing a Qt project which is using Qt linguist to support the translation. I have gone through the documentation and made my own .pro file for my project which is given below:

    HEADERS = CameraWidgetForPieChart.h \
    CameraDisplayManager.h \
    CameraUI.h \
    SOURCES = CameraWidgetForPieChart.cpp \
    CameraUI.cpp \
    CameraDisplayManager.cpp \
    main.cpp
    RESOURCES +=CameraUI.qrc
    TRANSLATIONS += translations/CameraUI_ba.ts

    # install
    target.path = C:/Oxscan/CameraUI
    sources.files = $$SOURCES $$HEADERS $$RESOURCES translations CameraUI.pro
    sources.path = C:/Oxscan/CameraUI
    INSTALLS+= target sources

    Then I have generated my own translation file CameraUI_ba.ts which is given bellow

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.0">
    <context>
    <name>CCameraWidgetForPieChart</name>
    <message>
    <source>Viewable</source>
    <translation type="obsolete">দেখতে পারবেন</translation>
    </message>
    <message>
    <source>Locked</source>
    <translation type="obsolete">লকড</translation>
    </message>
    <message>
    <source>Free</source>
    <translation type="obsolete">মেমরি খালি আছে</translation>
    </message>
    </context>
    <context>
    <name>CameraUI</name>
    <message>
    <source>Hello</source>
    <translation type="obsolete">আপনার ক্লিনিসিয়ান পিন প্রবেস করুন</translation>
    </message>
    </context>
    </TS>

    Then I use lupdate CameraUI.pro in the Qt command line and then lrelease to generate the .qm file. It is also generating the qm file.
    Now let me tell what is going wrong, it could not find out the classes I have used in my translation file. And when I am calling lupdate to my .pro file it is generating "translation type="obsolete"" as you can see from my .ts file. I dont know what is the problem. It could not find out the classes I have passed to my .ts file. I think the path specified in my .pro file has some problem. My project is stored in the c drive and in the oxscan directory(c:\oxscan\cameraui\).

    Any help will be appreciated.

    Regards
    Chandan

  2. #2
    Join Date
    Mar 2010
    Posts
    69
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problrm with Qt translation

    Hi everyone,
    I was so confused about the translation process in Qt and have gone through almost all threads available in qtcentre but the fact is I didn't get any clear solution. I have also seek help from Qt support team and they have given me some solution which was helpful but not as I have expected for my project. Anyway so I have follows the steps given below to solve my translation problem:

    Step 1: First make your Qt project
    Step 2: Use the tr() methods each and every places where you need the translation to take place
    Step 3: Now run your programme. I am using windows as my platform and visual studio 2008 as my IDE.
    Step 4: Now you will get a .pro file in the directory where your project solution is. If it is not there then go to visual studio again and go to your project,
    after that go to Qt menu->create basic .pro file.
    Step 4: Now go to the project folder and .pro file is waiting for you right there.
    Step 5: Right click on it and open with any text editor available in your windows and edit it as follows
    HEADERS = Sample.h \
    MainWindow.h \
    SOURCES = Sample.cpp \
    MainWindow.cpp \
    main.cpp
    RESOURCES +=CameraUI.qrc
    TRANSLATIONS += translations/use any name as you want.ts

    you need only the header files, the .cpp files, resourse file and add one more line as I have added in mine for the translation file.
    Step 6: Add a folder named translations in your project folder.Go to your Qt command prompt that is installed with Qt and available in the start menu->all programs->Qt by nokia v4.6.2(VS2008).
    Step 7: Now in the command prompt got to your project directory where your .pro file is available and then type lupdate your project name.pro and press enter,
    then type lrelease projectname.pro and press enter.
    Step 8: Now go to your project folder , then go to your translations folder and here is your .ts file and your .qm file.
    Step 9: Add the translation files in your Visual Studio project and add the .qm file to your resource.
    Step 10: Right click on the .ts file in translation filter of Visual Studio and open it with xml editor. Now change the contents as required and save it.
    Step 11: Now Right click on your .ts file you will get two option there one lupdate and then lrelease. First click lupdate then lrelease.
    Step 12: Compile the whole project and run it here is your change.
    Step 13: It is not working right may be you for got add the following three lines in you main.cpp
    QTranslator Translator;
    Translator.load("path for your .qm file");
    QApplication::installTranslator(&Translator);


    So I have got the solution of my translation problem by using those above steps. Hopefully these steps will help some other Qt developer or beginner as well.
    If anyone has any question regarding this post dont hesitate to contact me.

    Regards,
    Chandan

  3. The following user says thank you to chandan for this useful post:

    jazuju (4th July 2011)

Similar Threads

  1. Translation problems
    By Skepsor in forum Qt Programming
    Replies: 19
    Last Post: 16th June 2010, 20:04
  2. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 11:01
  3. Translation of app and Qt Dialogs
    By honza in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2009, 17:53
  4. setText translation
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2009, 15:59
  5. Translation
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 17:45

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
  •  
Qt is a trademark of The Qt Company.