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. QMessageBox buttons translation not working
Forum Updated to NodeBB v4.3 + New Features

QMessageBox buttons translation not working

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 4.0k Views 2 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.
  • D Offline
    D Offline
    Donald Duck
    wrote on last edited by Donald Duck
    #1

    I need to translate the buttons on a QMessageBox. For example if I have this code:

    QMessageBox::question(NULL, QObject::tr("Sure want to quit?"),  QObject::tr("Sure to quit?"), QMessageBox::Yes | QMessageBox::No);
    

    I would like to translate "Yes" and "No". After searching on the web, I found that I need to add this code to main.cpp (for Swedish):

    QTranslator translator;
    baseTranslator.load("qtbase_sv", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&baseTranslator);
    

    This works for French (replacing "qtbase_sv" with "qtbase_fr"), but when I try to translate it in Swedish (using "qtbase_sv"), the buttons are in English (it says "Yes" and "No" instead of "Ja" and "Nej"). How do I fix that?

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

      Hi
      Check there even is such file.
      C:\Qt\5.9.1\msvc2015_64\translations
      ( note compiler name)

      a---- 28-06-2017 14:54 165327 qtbase_bg.qm
      -a---- 28-06-2017 14:54 179242 qtbase_ca.qm
      -a---- 28-06-2017 14:54 174691 qtbase_cs.qm
      -a---- 28-06-2017 14:54 169653 qtbase_da.qm
      -a---- 28-06-2017 14:54 187985 qtbase_de.qm
      -a---- 28-06-2017 14:54 16 qtbase_en.qm
      -a---- 28-06-2017 14:54 165160 qtbase_es.qm
      -a---- 28-06-2017 14:54 161027 qtbase_fi.qm
      -a---- 28-06-2017 14:54 166157 qtbase_fr.qm
      -a---- 28-06-2017 14:54 173572 qtbase_gd.qm
      -a---- 28-06-2017 14:54 138680 qtbase_he.qm
      -a---- 28-06-2017 14:54 91101 qtbase_hu.qm
      -a---- 28-06-2017 14:54 161162 qtbase_it.qm
      -a---- 28-06-2017 14:54 129904 qtbase_ja.qm
      -a---- 28-06-2017 14:54 131255 qtbase_ko.qm
      -a---- 28-06-2017 14:54 153598 qtbase_lv.qm
      -a---- 28-06-2017 14:54 162972 qtbase_pl.qm
      -a---- 28-06-2017 14:54 157842 qtbase_ru.qm
      -a---- 28-06-2017 14:54 125753 qtbase_sk.qm
      -a---- 28-06-2017 14:54 158264 qtbase_uk.qm

      D 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Check there even is such file.
        C:\Qt\5.9.1\msvc2015_64\translations
        ( note compiler name)

        a---- 28-06-2017 14:54 165327 qtbase_bg.qm
        -a---- 28-06-2017 14:54 179242 qtbase_ca.qm
        -a---- 28-06-2017 14:54 174691 qtbase_cs.qm
        -a---- 28-06-2017 14:54 169653 qtbase_da.qm
        -a---- 28-06-2017 14:54 187985 qtbase_de.qm
        -a---- 28-06-2017 14:54 16 qtbase_en.qm
        -a---- 28-06-2017 14:54 165160 qtbase_es.qm
        -a---- 28-06-2017 14:54 161027 qtbase_fi.qm
        -a---- 28-06-2017 14:54 166157 qtbase_fr.qm
        -a---- 28-06-2017 14:54 173572 qtbase_gd.qm
        -a---- 28-06-2017 14:54 138680 qtbase_he.qm
        -a---- 28-06-2017 14:54 91101 qtbase_hu.qm
        -a---- 28-06-2017 14:54 161162 qtbase_it.qm
        -a---- 28-06-2017 14:54 129904 qtbase_ja.qm
        -a---- 28-06-2017 14:54 131255 qtbase_ko.qm
        -a---- 28-06-2017 14:54 153598 qtbase_lv.qm
        -a---- 28-06-2017 14:54 162972 qtbase_pl.qm
        -a---- 28-06-2017 14:54 157842 qtbase_ru.qm
        -a---- 28-06-2017 14:54 125753 qtbase_sk.qm
        -a---- 28-06-2017 14:54 158264 qtbase_uk.qm

        D Offline
        D Offline
        Donald Duck
        wrote on last edited by
        #3

        @mrjj No, there wan't that file, but I found a file named qt_sv.qm. If I use that file, it translates the half select color dialog (on this screenshot I've circled in green the translated parts and in red the non-translated parts), but it doesn't translate the yes and no buttons (the French qt_fr.qm translates everything). How can I make it translate everything in Swedish?

        Also, I have another question. Since the translated files are in a Qt folder, do I need to release them with the executable so that people who install my program but don't have Qt can use them? Or is that done automatically (in a DLL file, when compiling the executable or other)?

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

          @Donald-Duck said in QMessageBox buttons translation not working:

          How can I make it translate everything in Swedish?

          First read
          http://doc.qt.io/qt-5/linguist-overview.html

          Then open the corresponding TS file and have a look what is included.
          Then translate the rest and compile it.

          As far as you know you must include all qm with your installer.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Donald Duck
            wrote on last edited by
            #5

            Where do I find the TS file? I can only find QM files in that folder and they're already compiled so I can't really edit them. Or do I need to make my own TS file and translate everything myself, even the parts that are already translated?

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

              Hi
              I think they are included in the source code.
              You can use the maintenance.exe to install it.

              But please note that different text belongs to different files.
              like the msg text is from qtbase_ i guess. etc.

              I recommend a bit of research before fiddling around with it.

              D 1 Reply Last reply
              1
              • mrjjM mrjj

                Hi
                I think they are included in the source code.
                You can use the maintenance.exe to install it.

                But please note that different text belongs to different files.
                like the msg text is from qtbase_ i guess. etc.

                I recommend a bit of research before fiddling around with it.

                D Offline
                D Offline
                Donald Duck
                wrote on last edited by
                #7

                @mrjj Thanks for your help. I downloaded the source and I found the TS file and I'm going to start translating it. Is there any way I can share my work so that others also can use it?

                mrjjM 1 Reply Last reply
                1
                • D Donald Duck

                  @mrjj Thanks for your help. I downloaded the source and I found the TS file and I'm going to start translating it. Is there any way I can share my work so that others also can use it?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Donald-Duck
                  If you get svensk going, please post link to file here.
                  i will find out how we can get it included.
                  God fornøjelse :)

                  D 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Donald-Duck
                    If you get svensk going, please post link to file here.
                    i will find out how we can get it included.
                    God fornøjelse :)

                    D Offline
                    D Offline
                    Donald Duck
                    wrote on last edited by Donald Duck
                    #9

                    @mrjj I've uploaded a ZIP file containing the TS and QM files for my translation of qtbase_sv here: http://www.files.com/shared/59e610d1e9105/qtbase_sv.zip. This translation should be as complete as the French one (which is one of the most complete ones I've found).

                    1 Reply Last reply
                    1

                    • Login

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