Results 1 to 3 of 3

Thread: Use Translation file

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Use Translation file

    Hi all!

    I just start reading how to use the translator file and the QTranslator and I need some help to see if what I am doing is any close.

    the ts file
    Qt Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!DOCTYPE TS>
    3. <TS version="2.0" language="de" sourcelanguage="en">
    4. <context>
    5. <name>QObject</name>
    6. <message>
    7. <source>Username</source>
    8. <translation>Benutzername</translation>
    9. </message>
    10. <message>
    11. <source>Password</source>
    12. <translation>Passwort</translation>
    13. </message>
    14. </context>
    15. </TS>
    To copy to clipboard, switch view to plain text mode 

    Contructor of my class
    Qt Code:
    1. QString german = "C:/esp/lang/deutsch.ts"; QTranslator_Language.load(german);
    2. QCoreApplication::installTranslator(&_Language);
    3. ui.label->setText("Username");
    4. ui.label_2->setText("Password");
    To copy to clipboard, switch view to plain text mode 

    I was expecting that the Username would be translated to "Benutzername" and Password to "Passwort".

    I also tried _Language.translate function but didn't work.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use Translation file

    To use Translator you have to "wrap" visible strings.

    Qt Code:
    1. QString german = "C:/esp/lang/deutsch.ts";
    2. QTranslator _Language.load(german);
    3. QCoreApplication::installTranslator(&_Language);
    4. ui.label->setText(tr("Username"));
    5. ui.label_2->setText(tr("Password"));
    To copy to clipboard, switch view to plain text mode 
    Last edited by mcosta; 17th May 2011 at 18:08. Reason: spelling corrections
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Use Translation file

    Hi again.

    I just noticed that there is something wrong with the load command, as it return false..

    I also switch to ubuntu because there is where I fell more comfortable working with qt.

    my constructor has this:
    Qt Code:
    1.  
    2. if(Lang.load("/esp/Lang/de.ts")){
    3.  
    4. cout << "Loaded" << endl;
    5.  
    6. QCoreApplication::installTranslator(&Lang);
    7.  
    8. cout << QString(tr("Username")).toStdString() << endl;
    9. cout << QString(tr("Password")).toStdString() << endl;
    10.  
    11. }else cout << "Not Loaded" << endl;
    To copy to clipboard, switch view to plain text mode 

    I also tried to load with the line:

    Lang.load("de","/esp/Lang","ts");
    Lang.load("de","/esp/Lang",".","ts");
    Lang.load("de","/esp/Lang","","ts");

    my .pro file has the line:

    TRANSLATIONS = /esp/Lang/de.ts

    and my ts file was done with the linguist tool and is a copy of the skype ts file (see attachment)

    thanks!
    Attached Files Attached Files
    Last edited by ruben.rodrigues; 18th May 2011 at 11:02.

Similar Threads

  1. UI translation
    By Annihilator in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2010, 11:37
  2. translation
    By weixj2003ld in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2010, 01:01
  3. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 11:01
  4. Translation
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 17:45
  5. Replies: 5
    Last Post: 22nd September 2006, 08:04

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.