PDA

View Full Version : How to implement i18N whiling generating the GUI dynamically ?



CyberPunker
20th December 2016, 02:39
We want to generating the GUI dynamically through reading XML files, and at the same time ,the GUI should support i18N , so , the linguist method CAN NOT be implemented .

How to ?

anda_skoa
20th December 2016, 12:08
Are these your own XML files or are you loading QtDesigner .ui files via QUiLoader?

Cheers,
_

CyberPunker
21st December 2016, 15:37
NO, GUI's character is stored in the xml files, NOT in the source code , and I designed all the GUI by C++

CyberPunker
22nd December 2016, 01:59
the XML files are also designed by us , the C++ code generates the GUI according to the XML files. We don''t use the QtDesigner .

anda_skoa
22nd December 2016, 13:52
Ok, let me see if I understood that correctly.

* you have XML based descriptions of UI
* you have custom C++ code that loads such an XML and created QtWidgets accordingly
* the XML document contains text that should appear translated

Cheers,
_

CyberPunker
23rd December 2016, 17:05
Yes , just as your said

anda_skoa
23rd December 2016, 18:36
In order to get the strings for translation you need to extract them from the XML files.

You could write a tool like lupdate that does that and updates a Qt translation file, or generate a dummy cpp file that contains the strings in the QT_TR_NOOP macros and call lupdate on that.

Your loader needs to pass the loaded strings through the tr() function so that the translation lookup can find them.

Cheers,
_