[Kde-games-devel] kde game and i18n

Kleag kleag at free.fr
Tue Aug 16 19:51:04 CEST 2005


Hello Andreas,

Thank you for your answer. 

> However usually there are simpler solutions, depending on your situation.
> Why exactly do you require to send strings around?
>
I have to transmit to all clients messages like:
"X conquered Y"
"(X,Y,Z) <-> (A,B) ; Attacker loses N armies; Defender loses M armies."
"X attacks Y from Z with T armies."

> 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.
Well, I surfed through google and kde SVN, without finding... I'm maybe not 
very good at information search !

> 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;
>   ...
I finally successfully modified my method to do something like this: I 
transfer first the message to be translated (with a I18N_NOOP around it) and 
next its arguments. Upon receival I put the message in i18n and next uses arg 
functions to fill the arguments slots.

I will modify that to transfer only an ID for the message itself. You're 
right, it's a largely better solution. Passing all these strings over the 
network is a waste of bandwidth...

It's used like that:
  KStringVector messageParts;
  messageParts << I18N_NOOP("%1 attacks %2 from %3 with %3 armies.") 
    << currentPlayer()-> name() 
    << defender.name() 
    << attacker.name() 
    << QString::number(nb);
  broadcastChangeItem(messageParts, ID_STATUS_MSG2);

with broadcastChangeItem pushing the strings in the stream and sending it.

The following methods is called at receival time:
void KGameWindow::changeItem( KStringVector& strings, int id )
{
  kdDebug() << "KGameWindow::changeItem(KStringVector,int)" << endl;
  QString status2Text;
  strings >> status2Text;
  status2Text = i18n(status2Text);
  while (!strings.empty())
  {
    QString msgElem;
    strings >> msgElem;
    kdDebug() << "arg-ing " << status2Text << " with " << msgElem << endl;
      status2Text = status2Text.arg(msgElem);
  }
  changeItem(status2Text,id);
}

Finally the KStringVector is just a QStrings vector with operator>> and 
operator<< to fill it and empty it.

Thanks again.

Kleag
-- 
KsirK - a turn-based strategy game for KDE
http://gna.org/projects/ksirk

KGraphViewer - a GraphViz dot graphs viewer
http://gna.org/projects/kgraphviewer


More information about the kde-games-devel mailing list