如何使QT的翻译功能用起来更加简单 如何使QT的翻译功能用起来更加简单 How to make the translation function of QT easier to use
-
With the increasing size of projects, more and more UI controls are used. Every time a control is added, it needs to write a function to receive the LanguageChange event of Qt and call translation related functions in the event. What can be done to make it easier. I hope that each object can automatically translate the text they are responsible for when the LanguageChange event is published.
-
Creating a base widget that does that handling is the correct way. However you can't optimize more. Each of your widgets will have custom texts and that's normal so streamlining where the code should be is already a good gain.
-
Hi,
Are you coding all your UIs ?
If so, you can create a base class that implements the LanguageChange event handling that will call a virtual method named, for example,
retranslateUi
that you will re-implement in all your widgets. You should call that method from the constructor as well and place there all calls that set translatable texts on your widgets. -
Creating a base widget that does that handling is the correct way. However you can't optimize more. Each of your widgets will have custom texts and that's normal so streamlining where the code should be is already a good gain.
-