[Kde-games-devel] KScoreDialog and KGameDifficulty bugs
Matt Williams
matt at milliams.com
Sun Apr 27 21:12:52 CEST 2008
Hey everyone,
I went through my KScoreDialog bugs trying to track down the reasons for them.
Most of the bugs were related to i18n which is often a cause for confusion
for me :)
Before I talk about the bugs I first need to explain how KScoreDialog works,
particularly with respect to the score groups. When you pass a group name
string to KScoreDialog::setConfigGroup() it is that string which is used as
the KConfig group name. Because of this is it necessary to pass the string
through an I18N_NOOP(). This has the effect that the string is added to the
database to be translated but it is still the raw (untranslated) string that
is passed to KScoreDialog and then used as the group name. Later on, inside
KScoreDialog when the group name is due to be displayed to the UI it is
passed through i18n() which displays the translated string from the game's
translation database.
There became a problem when KGameDifficulty came out and and many games
started using it (but not ksquares which is why I haven't noticed this until
now) in that games would do setConfigGroup(KGameDifficulty::levelString()).
This is a problem since KGameDifficulty::levelString() returns a translated
string! This had two effects: firstly that KScoreDialog would save the scores
to a different KConfig group depending on what language the game was run as
and secondly that when KScoreDialog came to run i18n() over the group name
for display in the UI it was being passed an already translated string
(either directly or via the config file) and so bugs were cropping up.
To get around all this I've added a function to KGameDifficulty which returns
the level difficulty but as an untranslated string (it is however passed
through I18N_NOOP() so that KScoreDialog can display the translated version
to the UI later). It is this string which must be passed to KScoreDialog
(KGameDifficulty::untranslatedLevelString()).
The attached patch adds this function and patches Kollision, KMines and
KNetwalk to use it correctly. I've tested it with Kollision with the x-test
language (I couldn't get the other two to work correctly with x-test but the
patch still stands). and in fact allows me to close about 4 different bugs
which had been assigned to KScoreDialog :D
The only downside to this is that there's now duplication in the strings
needing to be translated, i.e. there's both a
I18N_NOOP("Easy");
and a
i18nc("Game difficulty level 3 out of 8", "Easy");
since the i18n() call in KScoreDialog can't match its no-context string to the
i18nc() string entry. This shouldn't be a problem but I though I'd mention
it.
There's probably a number of other games out there which are using
KGameDifficulty and have this same bug which I haven't mentioned in the patch
so be sure to patch your game if you might be suffering from this bug. Even
if you're not using KGameDifficulty you will need to make sure that any
string which you pass to KScoreDialog::setConfigGroup() is in its
untranslated form but has, at some point, been passed through an I18N_NOOP().
I've updated both the apidocs and the techbase tutorial [1] to reflect this.
If anyone's got any real complaints about this then reply here but this email
is mostly for your information. I'll commit tomorrow if there's no
complaints.
Regards,
Matt Williams
[1] http://techbase.kde.org/Development/Tutorials/Games/Highscores
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scoredifficultybug.patch
Type: text/x-diff
Size: 8033 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-games-devel/attachments/20080427/4b3a4fd4/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kde-games-devel/attachments/20080427/4b3a4fd4/attachment.pgp
More information about the kde-games-devel
mailing list