[Kde-games-devel] kde game and i18n

Andreas Beckermann b_mann at gmx.de
Tue Aug 16 13:40:04 CEST 2005


On Tuesday 16 August 2005 13:23, Kleag wrote:
> Hello,
>
> I don't know how to handle i18n in network mode for my game KsirK: I forge
> messages in a client to be displayed, internationalized, in all other

Ouch (see below).

> clients. I made a special container class that is filled with not i18ned
> messages parts. These parts are then transmitted over the network with
> KGame::sendMessage and they are then extracted and given to the i18n(...)
> function.
>
> There is problems with this approach:
> 1. I was not able to find the i18n() function definition, so I'm not sure
> that it will be able to translate strings given at runtime;

What do you mean by "not able to find the i18n() function definition" ?
It is declared in klocale.h and defined in klocale.cpp of kdelibs/kdecore.

> 2. I don't know how to mark strings in my code to be extracted by the tool
> that makes the .pot file;

See below

> 3. With this method, I cannot write strings to be translated like that:
> '... ("ABC %1 XYZ").arg(t)' but I have to write '... << "ABC " << t << "
> XYZ" which does not allow a good translation as soon as there is words
> order changes between languages.
>
> Does anyone know how to cleanly handle i18n of strings in sent to different
> languages clients ?

Yes: Don't do that. It's a design flaw.
In theory you would require your game to send out _all_ languages that your 
game is translated in. Or at least all languages that the participating 
clients use. This is evil. Very evil.

Why don't you just send IDs and convert them into i18n()'ed strings on 
receival? I.e.
  class SomeClasss {
    enum MessageIds {
       YouLost = 0,
       YouWon = 1,
       Whatever = 2,
       Foobar = 3
    }
  };
and on sending:
  sendMessage(SomeClass::Foobar, msgid);
when receiving:
QString string;
int id;
stream >> id;
switch (id) {
  case SomeClass::Foobar:
    string = i18n("Foobar");
    break;
  ...
}

(the same is possible with QString IDs, of course. You don't require an enum 
class then)

However usually there are simpler solutions, depending on your situation. Why 
exactly do you require to send strings around?

> Thanks in advance.
>
> Kleag

CU
Andi


More information about the kde-games-devel mailing list