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. [SOLVED] Translating QLineEdit context menu
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Translating QLineEdit context menu

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

    I would like to translate default QLineEdit context menu. I've found a similar topic qt-project.org/forums/viewthread/22203. I know that I should use QApplication::installTranslator() but I don't know which translation file I should load or I should create a new file?

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

      Hi,

      "Here":http://doc.qt.io/qt-5/i18n-source-translation.html you have the starting point to create translatable code as well as setup your project (create translation files, load them etc.).

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

        I loaded the file which contains translations of these strings and now it works properly. But I would like to add as well another file with my own strings. I created .qm file and tried to load it but it doesn't work. Is it possible to load several translation files?

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

          Yes it is, just load them all at your application startup. IIRC you can also combine several of them in only one file.

          How did you generate your custom file ?

          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
          • M Offline
            M Offline
            mikaelo
            wrote on last edited by
            #5

            I added this line to .pro file:
            @TRANSLATIONS += file_name_pl.ts@

            Then I run Tools > External > Linguist > Update translations (lupdate) which generated .ts file. I opened this file with Linguist and added translations of strings.
            Then I run lupdate and Tools > External > Linguist > Compile translations (lrelease) which generated .qm file. I also added these lines to .cpp file and run the application:
            @QTranslator Translator;
            Translator.load("file_name_pl");
            app.installTranslator(&Translator);@

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

              You are giving it a relative path, did you copy that file in the same folder as the application ?

              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
              • M Offline
                M Offline
                mikaelo
                wrote on last edited by
                #7

                I loaded the translations file before I created a window but I also had to use an absolute path. There is probably some bug because I couldn't use a relative path.

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

                  When using a relative path you must ensure that everything is copied in the right place i.e. the application folder.

                  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