Page 1 of 1
Translation text inside notification
Posted: 02 June 2015, 20:19
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?
Re: Translation text inside notification
Posted: 02 June 2015, 20:48
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.
Re: Translation text inside notification
Posted: 02 June 2015, 21:45
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
Re: Translation text inside notification
Posted: 03 June 2015, 00:08
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 ^^
Re: Translation text inside notification
Posted: 05 June 2015, 18:22
by tarini