[Kde-games-devel] Parsing and translating XML game-data

Josef Spillner spillner at kde.org
Thu Nov 30 14:07:47 CET 2006


Am Donnerstag, 30. November 2006 07:22 schrieb Ian Wadham:
> What I really want is is a function which will give me all
> the raw text as a QByteArray in its original UTF-8 encoding.
> That is what I need to pass to the translators at build-time
> and to the translation process "i18n()" at run time.

Slightly off-topic:
I've also thought about using xml:lang for translations. This is part of the 
XML specification but apparently only few people make use of it. For the KDE 
translation process, having external translations seems to be a more natural 
thing (especially for translators) but still I'd like to see some true 
inside-xml i18n :)

> I can use QDomElement::text().toUtf8().  It gets back a "u"
> with umlaut in 2 bytes as expected, but I am not sure I get
> back all my whitespace and I certainly *lose* the format tags.

You can use:
QString foo;
QTextStream bar(&foo);
bar << your_element;

Then foo contains a serialised form of the XML, i.e. a section of what was in 
the XML file originally.

In XML, whitespace is significant in the content of a tag. So XML 
(de)serialisers should not simply strip it, but the Qt function already does 
formatting of some sort (line breaks and such). In general it should be ok 
for you though.

> Is there some simple way to get back all my original text
> without alterations?  Or should I abandon XML, use some
> simple home-grown format and hand-code the parsing?  Or
> maybe use KSimpleConfig?

I think using XML for game data is fine, a lot of games switched to doing so 
since the X stands for eXtensible and this has proven to be a good thing. Of 
course translating rich-text is something translators have to be aware of but 
otherwise it's fine.

Josef


More information about the kde-games-devel mailing list