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. QTranslator issue
Forum Updated to NodeBB v4.3 + New Features

QTranslator issue

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k 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.
  • B Offline
    B Offline
    b1gsnak3
    wrote on last edited by
    #1

    Hello...

    I have one minor question...

    I am trying to use QTranslator class to translate to any given language... I tried using french and polish (by forcing the use of qt_fr and qt_pl) but it seems that it doesn't translate... Here is the test code I used...

    @
    #includes

    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QTranslator qtTranslator
    qtTranslator.load("qt_fr", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    QTranslator myTranslator;
    myTranslator.load("qt_fr");
    app.installTranslator(&myTranslator);

    qDebug() << QObject::tr("cancel");
    return app.exec();
    }
    @

    this prints the normal cancel... Don't know the French word but the polish word is Annuluj or something like that (as it says in the documentation)... Are there any other steps required for the translator to work? Tried using the lupdate from cmd but it still does nothing... Any help would be much appreciated... Also when I use lupdate it says this: "No TS files specified. Only diagnostics will be produced for *.pro"

    Using Qt 4.8.4 with MSVC2008 but the QtCreator from Qt 5... Windows 7 Proffesional 32 bits... Is it possible to be because the OS doesn't support language packs? This souldn't be an issue though because I'm forcing the translations from the Qt Translation Folder... No? Thank you in advance

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      I think you be a little bit confused about how QTranslator works.

      When you need a translation, you must provide a CONTEXT.
      In the global context (you use it when call the static version of tr) there's no translation for "cancel" it qt_*.ts.

      In this example
      @ int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

       QTranslator translator;
       translator.load("hellotr_pl");
       app.installTranslator(&translator);
      
       QPushButton hello(QPushButton::tr("Hello world!"));
       hello.resize(100, 30);
      
       hello.show();
       return app.exec();
      

      }@

      To translate "Hello World" you need to create a translation file "hellotr_la.qm" and use it.

      No global translation for "cancel" was provided by qt_*.ts

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      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