Results 1 to 6 of 6

Thread: Translation of Shortcuts

  1. #1
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Translation of Shortcuts

    Hello!

    I have a problem with the translation of shortcuts in the QCreator.

    I can shortcuts to menu entries in the designer of the QtCreator. This works
    and I can use the shortcut in the program.

    But if I add a translation to the shortcut (in Germany "Ctrl-P" is "Strg-P") using
    the "qt-linguist" tool, the displayed shortcut vanishes from the menu and they
    do not work any more.

    If I deactivate the translation, it will work again.

    I even tried to load the "Qt translations" (as mentioned in another post) by using
    the following code, but it did not help:

    Qt Code:
    1. qt_translator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath)+"/qt_de");
    2. installTranslator(&qt_translator);
    To copy to clipboard, switch view to plain text mode 

    Does anyone know a solution for this problem?

    Regards
    Sven

  2. #2
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Translation of Shortcuts

    I'm still interested in a solution for this problem...
    If nobody else have this problem, what do I'm wrong?!

  3. #3
    Join Date
    Jul 2015
    Location
    Sweden
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Translation of Shortcuts

    To be honest I don't think translations for shortcuts is there for translated UI texts. It's only there so you can change the keys used by shortcuts in different languages.

    Looking at the source generated by Creator it looks like the text returned from translations goes directly into QAction::setShortcut and it invokes the QKeySequence::QKeySequence QString constructor. And from that I guess you can see where this is going...

    There is no way that I can see where you can setup a separate display text for a shortcut sequence. But looking at QKeySequence::toString I think you'll be able to see a solution. There must be a German translation for "Ctrl" in your resource files (in the "QShortcut" context) and then things might work as you expect. Just make sure NOT to check the translatable option for your shortcuts unless you need to change the actual keys pressed in other languages. And the translations in that case must still use the default Alt+, Shift+, Ctrl+ format or the QKeySequence constructor will fail to create a shortcut.

    FYI. Just guessing from reading the docs, not tested for real yet. But I'm going there my self in the near future...

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Translation of Shortcuts

    Hi, maybe QKeySequence (Qt::CTRL | Qt::Key_P) works.

    Ginsengelf

  5. #5
    Join Date
    Mar 2017
    Location
    New Hampshire, USA
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translation of Shortcuts

    I just saw this question and I have had the same problem. The problem is resolved by installing multiple translators - one for your application and one for qt. I created a setLanguage() method for my application class that loads both of these translators:

    Qt Code:
    1. void DwbApplication::setLanguage(QLocale locale)
    2. {
    3. if (m_qtXlator.load(locale, QLatin1String("qt"), QLatin1String("_"), QLatin1String(":/qtTranslations")))
    4. {
    5. installTranslator(&m_qtXlator);
    6. }
    7. if (m_dwbXlator.load(locale, QLatin1String("dwb_lang"), QLatin1String("_"), QLatin1String(":/translations")))
    8. {
    9. installTranslator(&m_dwbXlator);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    In my case, I support English and German and I included qt_de.qm and qt_en.qm in a qtTranslations folder in my resource file. What's most important is that the application can find the file at runtime when it loads the translator.

    The qt_xx.qm files can be found in the translations folder under your compiler toolchain folder, e.g. C:\Qt\Qt5.8.0\5.8\mingw53_32\translations in Windows (when Qt is installed in C:\Qt) or /opt/Qt/5.8/gcc_64/translations in Linux (when Qt is installed in /opt/Qt).

    I hope this helps.

    Jim

  6. #6
    Join Date
    Mar 2017
    Location
    New Hampshire, USA
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Translation of Shortcuts

    There is one thing I forgot to mention in my previous post and this may be your issue since you are loading the Qt UI files.

    If you look at the Qt translation files, (I'm running on windows so they are in C:\Qt\Qt5.8.0\5.8\mingw53_32\translations), you will see that qt_de.qm is suspiciously small. In fact, the Qt Linguist Manual states:
    In Qt 5, the .qm files were split up by module and there is a so-called meta catalog file which includes the .qm files of all modules. The name of the meta catalog file is identical to the name of Qt 4's monolithic .qm file so that existing loader code works as before provided all included .qm files are found.

    A solution is to use lconvert to build your own qt_de.qm that contains the strings for the modules that you need, for example,
    Qt Code:
    1. lconvert -o installation_folder/qt_de.qm qtbase_de.qm qtdeclarative_de.qm
    To copy to clipboard, switch view to plain text mode 
    This can then be added to your resource file and QTranslator can load it without any problem.

    An alternate solution is to put all of the .qm files for Qt (assistant_cs.qm, assistant_da.qm, assistant_de.qm, ...) into your resource file. Then when you load the meta-file, qt_de.qm, it will load fine because it will find all the files it references.

Similar Threads

  1. Help with QT shortcuts?
    By fluffaykitties in forum Qt Programming
    Replies: 12
    Last Post: 16th April 2018, 14:32
  2. qml key shortcuts
    By antialias_forum in forum Qt Quick
    Replies: 0
    Last Post: 22nd December 2010, 15:45
  3. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 14:18
  4. Pb with shortcuts on Mac OS
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2008, 20:22
  5. Creatin Key Pad shortcuts
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 19th May 2006, 06:50

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.