PDA

View Full Version : Dynamic Language Switching



Salazaar
8th June 2007, 12:40
Hi. I've got a problem. I'd like to do dynamic language switching in my application, but there's a problem. In my book it is explained how to do it designing forms manually, not by designer. I created forms using designer. The problem is, that function createLanguageMenu() is very different than usual. And (I think) I can't make it by subclassing QMainWindow. Do you know what I mean? Have you got any ideas how to do it ?Regards

patrik08
8th June 2007, 17:04
Hi. I've got a problem. I'd like to do dynamic language switching in my application, but there's a problem. In my book it is explained how to do it designing forms manually, not by designer. I created forms using designer. The problem is, that function createLanguageMenu() is very different than usual. And (I think) I can't make it by subclassing QMainWindow. Do you know what I mean? Have you got any ideas how to do it ?Regards

Chapter 17 from http://trolltech.com/developer/documentation/books/2 german version ...
the code is not on cd....

http://doc.trolltech.com/4.3/qtranslator.html detroy truncate the actual language and load a new ... translator file... on qmainwindow .

http://doc.trolltech.com/4.3/qcoreapplication.html#removeTranslator
http://doc.trolltech.com/4.3/qcoreapplication.html#installTranslator

jpn
9th June 2007, 14:23
I'm not sure if I understood the problem but hopefully this wiki article helps: Dynamic translation (http://wiki.qtcentre.org/index.php?title=Dynamic_translation).

Salazaar
10th June 2007, 18:06
Thanks a lot, I'll read it. Regards

Salazaar
29th June 2007, 11:24
No, that links didn't solve the problem. The problem is, that createLanguageMenu is different that, let's say, createFileMenu, and I am designing forms in designer, so I can't change createLanguageMenu without accessing ui_.h file code. And I'd like to know, how to do dynamic language switching when you were designing forms by designer, not manually. Regards

jpn
29th June 2007, 11:38
It's done in code for the reason that usually you don't want a static hard coded language menu (done in designer) but rather a dynamic menu loaded according to detected language files. This way new language files can be added later without recompiling the application.

Salazaar
29th June 2007, 11:47
It's done in code for the reason that usually you don't want a static hard coded language menu (done in designer) but rather a dynamic menu loaded according to detected language files. This way new language files can be added later without recompiling the application.
I don't understand I'd like dynamic language switching, without necessity to rebuild application or run it again

jpn
29th June 2007, 12:00
I don't understand I'd like dynamic language switching, without necessity to rebuild application or run it again
You can do this with actions created in designer. You still might want to instantiate a QActionGroup or QSignalMapper in code instead of creating separate slots for each action. Then just switch the language according to the action (it's up to you whether you use text, objectName, data, or something else).

However, I was talking about flexibility with adding new translations. If you create language actions in designer, you will have to add a new action and recompile the application if you later decide to add a new translation to your application.