PDA

View Full Version : Qt Multi language app at runtime



vhptt
23rd July 2012, 05:50
I'm developing an app which supports switching language at runtime. I've read a lot of tutorial and qt Internationalization ... and I know the way to do is remove current translator and install new translator, then call method retranslateUi() to refresh view.
If i use drag and drop feature, then qt generate method retranslateUi() and I don't need to implement it. But, if my form is manually implementation or implement a model of a table, so I must implement method retranslateUi() which is reset all text. This takes a lot of effort.
Does someone know another way to make qt component automatically change text when even languageChange emitted without implement retranslateUi() method for each form ?

sonulohani
23rd July 2012, 07:41
Hey, That is the only way for the language translations. Call retranslateUi() function. It is must. If you want to do it by another method then, delete the object of this widget and create it again when you're selecting the language. Note: Before deleting first install your translation file and then delete it.

wysota
23rd July 2012, 15:23
Does someone know another way to make qt component automatically change text when even languageChange emitted without implement retranslateUi() method for each form ?
Sure, you can hire someone to write it for you :D

And seriously, all user-visible texts need to go through tr() again, there is no other way. If you want your code to be translatable, you have to move setting user-visible values to a separate method and then call that method from both the constructor and from LanguageChange event (it doesn't have to be called retranslateUi).