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

Qt Localizing Windows

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k 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
    jamesxL
    wrote on last edited by
    #1

    My project folder is currently setup like this:
    @
    -root
    ---[source files]
    ---Translations
    ------app_en.ts
    ------app_en.qm
    ------app_fr.ts
    ------app_fr.qm
    ------app_jp.ts
    ------app_jp.qm
    @

    My .pro file:
    @
    #-------------------------------------------------

    Project created by QtCreator 2014-03-18T15:15:40

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = TestApp
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp
    TRANSLATIONS=Translations/app_en.ts
    Translations/app_fr.ts
    Translations/app_jp.ts
    CODECFORSRC = UTF-8

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui
    @

    In my main.cpp I try to force the translation to JP:
    @
    #include "mainwindow.h"
    #include <QApplication>
    #include <QTranslator>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QTranslator translator;
    translator.load("app_jp");
    a.installTranslator(&translator);
    MainWindow w;
    w.show();

    return a.exec(&#41;;
    

    }
    @

    But the main window still appears in English. Maybe I'm misunderstanding the documentation, but how do we force a certain local for the application?

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

      Hi,

      Are you sure your translation are loaded properly ? If I see things correctly, all your translation files are within your project sources. You application is run from the build directory so it can't find them. So you can either copy the files besides your executable, give the path where to find them to QTranslator or use the resource system.

      Hope it helps

      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
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote on last edited by
        #3

        Look at this project
        http://kde-apps.org/content/show.php/BackupTo?content=149622
        and download it. The it - en translations work very well. You can also embed in the exe the localizations file.

        Need programmers to hire?
        www.labcsp.com
        www.denisgottardello.it
        GMT+1
        Skype: mrdebug

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

          I've created a resource file entry for each one of my .qm files then added the resource to the projet. At the start up I load the resource and the path provided is:
          @translator.load(":/Translations/app_jp.qm");@
          and it works well I guess I needed to put in a full path to .qm file if I wasn't using resource file, but this way seems much simpler

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

            Indeed, that's a catch many people fall in currently, the source tree is not the build tree so using relative path will never have the expected effect

            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

            • Login

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