Translation on server side based on current player, not client?
Posted: 04 November 2020, 14:24
I am translating something before it gets sent to the notification. However this is what BGA recommends and other projects use as a design pattern
en.doc.boardgamearena.com/Translations#On_server_side_.28PHP.29
notif=clienttranslate("foo");
self::notifyAllPlayers( 'log', notif); // GOOD
cribbage code
Some are clienttranslate if it is a pass through
some are _ if it is a variable replacement
An example of variable replacement is
However something unexpected is happening, the same text is only being translated based on the player who made the play. Not the player who gets the notification.
https://imgur.com/a/UR1bfov
As I am typing I am thinking the javascript may be the issue
What am I doing wrong and what is the correct way to pass text from server to client THEN translate it (if that is the issue)
en.doc.boardgamearena.com/Translations#On_server_side_.28PHP.29
notif=clienttranslate("foo");
self::notifyAllPlayers( 'log', notif); // GOOD
cribbage code
Code: Select all
$this->translations = array(
"pair_score_info" => clienttranslate('${player_name} scores a pair for 2 points'),
"trips_score_info" => clienttranslate('${player_name} scores trips for 6 points'),
"quads_score_info" => clienttranslate('${player_name} scores quads for 12 points'),
"run_score_info" => clienttranslate('${player_name} scores a run for ${points} points'),
"fifteen_score_info" => clienttranslate('${player_name} scores a 15 for 2 points'),
"thirtyone_score_info" =>clienttranslate('${player_name} scores a 31 for 2 points'),
"pair_score_text" => clienttranslate('Pair for 2 points'),
"trips_score_text" => clienttranslate('Trips for 6 points'),
"quads_score_text" => clienttranslate('Quads for 12 points'),
"run_score_text" => self::_("Run for %s points"),
"fifteen_score_text" => clienttranslate('15 for 2 points'),
"thirtyone_score_text" => clienttranslate('31 for 2 points'),
"runningTotal" => clienttranslate('Running Total ${total}'),
"flush_hand" => self::_("Flush for %s "),
"nobs_hand" => self::_("Nobs for %s "),
"fifteen_hand" => self::_("15 for %s "),
"pair_hand" => self::_("Pair for %s "),
"run_hand" => self::_("Run for %s "),
"hand_total" => clienttranslate('Player ${player_name} has scored ${points} points with their ${hand}:<br/>${details}'),
"crib"=>clienttranslate('Crib'),
"hand"=>clienttranslate('Hand'),
"cutCard"=>clienttranslate('Cut Card'),
"cutDraw" => clienttranslate('... it\'s a tie, redraw'),
"cutWin" => self::_("%s wins"),
"cutDetail" => clienttranslate('${Player1Name} cut ${card1}, ${Player2Name} cut ${card2}, ${message}')
);
some are _ if it is a variable replacement
An example of variable replacement is
Code: Select all
$run_points = self::findRun($copy_cards);
if ($run_points > 0) {
// score
self::notifyAllPlayers('score', $this->translations["run_score_info"], array (
'player_id' => $player_id,
'player_name' => self::getActivePlayerName(),
'points' => $run_points,
'score_text' => sprintf($this->translations["run_score_text"], $run_points)
));
$pointsScored += $run_points;
https://imgur.com/a/UR1bfov
As I am typing I am thinking the javascript may be the issue
Code: Select all
dojo.place(
this.format_block('jstpl_scorePeg', {
id: id,
scoreText:notify.args.score_text + ' '
} ), 'playertablename_'+notify.args.player_id);