Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

**cool functionality** Can the user translate the application at runtime?



  • Hello to everyone,
    I'd like to add a (IMHO) cool functionality to give at my customer a possibility to translate the application at runtime!

    I'd like to reproduce the same behavior of Qt Creator, so double click on a QLabel, or a QPushButton or any widgets to bring up a white line edit where the user can write the best text in his language.

    Do you have any idea... how to do it?
    Thank you, as always.


  • Moderators

    @addebito hi,

    take a look into the documentation, with this example

    https://doc.qt.io/qt-5/qtlinguist-hellotr-example.html

    it should get you started :)



  • Hi @J-Hilk ,
    thank you for your kind reply however I know how Qt translation works.
    I already have an application with the GUI runtime translation and without restarting, but now I'd like to give at my customers the possibility to translate the GUI directly with itself.

    As mentioned before, the user should be able to enter in this "runtime translation" with a double click on a widget (as the same behavior of Qt Creator) write the best word in his language and press Return to confirm it.
    Under the wood I'll update the .ts file, rebuild the .qm file and reload it.

    It might work?
    But my first question was... how to do the functionality "double click" on all widgets (like QtCreator GUI side) to translate the text at runtime?

    Thank you.



  • you can either:

    1. subclass each QWidget subclass (QLabel, QPushButton, etc.), which you'd like to apply this double-click feature on it, implement mouseDoubleClickEvent and show a QLineEdit on top of that widget, and so on.
    2. create a QObject-based class and implement eventFilter. then for every QWidget-based widget, installEventFilter on that class' instance. (Im not sure about this to work, actually :) )

    But I don't know how to modify ts and qm files. I think It's better to embed lupdate and lrelease in your application, or take a look at their source code



  • Thank you at all.


  • Moderators

    @addebito if you plan to update your ts file by hand, take a look at my phrasebook utility tool
    https://github.com/DeiVadder/QtPhrasebookUtilityTool

    I use it to update/patch my ts files, should help you getting started.


Log in to reply