Translation text inside notification

Game development with Board Game Arena Studio
Post Reply
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

Translation text inside notification

Post by tarini »

Hi, I've got a doubt.

In my material.php I have a list of array that rappresent each game cards.
One of the "field" is a description.
Description is useful only on the client, to show the card effect inside a tooltip; they are never used server side.

These card objects are sent to the client through notifyPlayer methods or getAllDatas for setup and for any user refresh.
My question is: what are the right translate method for the cards description? clienttranslate() or _().

Reading documentation it seem that the right method is clienttranslate (http://en.doc.boardgamearena.com/Transl ... _.28PHP.29 second example).

Can you confirm?
User avatar
daikinee
Posts: 32
Joined: 19 November 2011, 01:19

Re: Translation text inside notification

Post by daikinee »

What i've done is Assyria:

$this->CARD_TYPE_TRANSLATIONS = array(
'barley' => clienttranslate('barley(s)'),
'date' => clienttranslate('date(s)'),
'grape' => clienttranslate('grape(s)'),
'palm' => clienttranslate('palm(s)'),
'plow' => clienttranslate('plow'),
'salt' => clienttranslate('salt(s)'),
'wild' => clienttranslate('wild')
);

Then:

self::notifyAllPlayers("foodCardUsed", clienttranslate('${player_name} uses ${card_number} ${card_icon} ${card_type}'), array(
'i18n' => array('card_type'),
'player_id' => $activePlayerId,
'player_name' => self::getActivePlayerName(),
'card_number' => $card['type_arg'],
'card_icon' => self::getIcon($card['type']),
'card_type' => $this->CARD_TYPE_TRANSLATIONS[$card['type']],
'card' => $card
));

Don't forget the 'i18n' field. It's says that the 'card_type' parameter should be translate. It's written somewhere in the BGA documentation.
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

Re: Translation text inside notification

Post by tarini »

My case is more complicated

I have an object like this:

Code: Select all

$card = array(
  'description' => clienttranslate('blablabla'),
  'cost' => 1000
)
and i send to the client in this way:

Code: Select all

notifyPlayer(12345, 'message', array(
  'card' => $card
));
I don't have a to-translate property, but a complex object
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Translation text inside notification

Post by pikiou »

You can translate text on the client side using the _() function:

Code: Select all

var html = "<h4>" + _(card.title) + "</h4><hr />";
if(card.description.length > 0) html += _(card.description) + "<br/>";
Do remember that any literal string you will translate at execution time has to go through clienttranslate() or _() at least once somewhere in your code, so the pre-parser can identify all the literal strings to translate.
You did so in your material.inc.php so it's all good ^^
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

Re: Translation text inside notification

Post by tarini »

:mrgreen: :mrgreen:
Post Reply

Return to “Developers”