Page 2 of 3

Re: Translation on server side based on current player, not client?

Posted: 18 November 2020, 01:51
by RicardoRix
when you include a variable in the clienttranslate string, you need to write it like this:

${points}

rather than

$points

You have to think of ${points} as a placeholder that the clienttranslate will magically replace for you.

Re: Translation on server side based on current player, not client?

Posted: 18 November 2020, 13:18
by MikeIsHere
For the Runs I tried
"run_score_text" => clienttranslate('Run for ${points} points'),

But that didn't work either so I just listed out all 5 possibilities, with no replacement.
And even still that string is not being translated ?!?

for
"cribText"=> clienttranslate('Crib +${points} points'),
"handText"=> clienttranslate('Hand +${points} points'),

That didn't work either so I just do a replacement on the js side.

Re: Translation on server side based on current player, not client?

Posted: 18 November 2020, 22:10
by Tisaac
I still don't understand what you are doing with these strings.
Here is how the translating works :
- on backend, only the self::_() actually performs a translation, using the current player as a reference. Notice that self::_() is also a marker used by the BGA script to find all the translatable strings
- the other strings you want to translate on backend need a "totranslate" or "clienttranslate" marker in front of it to be found by the BGA script, but these functions are doing nothing to the string itself
- when you are sending a notification, the message is automatically translated on the client
- any other strings must be translated using _() on client side, even if you put clienttranslate on backend (which again is just a marker)

Re: Translation on server side based on current player, not client?

Posted: 19 November 2020, 01:44
by MikeIsHere
What I am failing to understand is why sometimes the same pattern works and sometimes it does not. I did go through many iterations so you do have to ignore the first couple of post but here is the current code

In the php constructor I wrap all my translateables in an associated array and each element uses clienttranslate, and each string is available to be translated.

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'),
            "run3_score_text" => clienttranslate('Run for 3 points'),
            "run4_score_text" => clienttranslate('Run for 4 points'),
            "run5_score_text" => clienttranslate('Run for 5 points'),
            "run6_score_text" => clienttranslate('Run for 6 points'),
            "run7_score_text" => clienttranslate('Run for 7 points'),
            "fifteen_score_text" => clienttranslate("15 for 2 points"),
            "thirtyone_score_text" => clienttranslate('31 for 2 points'),
            "rightJack_score_text" => clienttranslate('Right Jack for 2 points'),
            "lastCard_score_text" => clienttranslate('Last Card for 1 point'),
            "go_score_text" => clienttranslate('GO for 1 point'),
            "runningTotal" => clienttranslate('Running Total ${total}'),

            "flush_hand" =>  clienttranslate('Flush for %s  '),
            "nobs_hand" => clienttranslate('Nobs for %s  '),
            "fifteen_hand" => clienttranslate('15 for %s  '),
            "pair_hand" => clienttranslate('Pair for %s  '),
            "run_hand" => clienttranslate('Run for %s  '),
            "hand_total" => clienttranslate('Player ${player_name} has scored ${points} points with their ${hand}:<br/>${details}'),

            "crib"=> clienttranslate('Crib'),
            "hand"=> clienttranslate('Hand'),
            "cribText"=> clienttranslate('Crib +${points} points'),
            "handText"=> clienttranslate('Hand +${points} points'),
            "cutCard"=> clienttranslate('Cut Card'),
            
             "cutDraw" => clienttranslate('... it\'s a tie, redraw'),
             "cutWin" =>  clienttranslate('%s wins'),
             "cutDetail" => clienttranslate('${Player1Name} cut ${card1}, ${Player2Name} cut ${card2}, ${message}')            
        );
And now adding the i18n parameter some strings get translated, some do not and as far as I can tell they all follow the same design pattern

This works

Code: Select all

            $score_text = ($pairs == 1) ? $this->translations["pair_score_text"] : (($pairs==2) ? $this->translations["trips_score_text"] : $this->translations["quads_score_text"] );
            $info_text = ($pairs == 1) ? $this->translations["pair_score_info"] : (($pairs==2) ? $this->translations["trips_score_info"] : $this->translations["quads_score_info"] );
            self::notifyAllPlayers('score', $info_text, array (                
                'player_id' => $player_id,                
                'player_name' => self::getActivePlayerName(),
                'points' => $value,
                'pairs' => $pairs,
                'score_text' => $score_text,
                'i18n' => array('score_text')
            ));
and so does this

Code: Select all

self::notifyAllPlayers('score', $this->translations["thirtyone_score_info"], array (                
                'player_id' => $player_id,                
                'player_name' => self::getActivePlayerName(),
                'points' => 2,
                'score_text' => $this->translations["thirtyone_score_text"],
                'i18n' => array('score_text')
            ));
Even the ones with replacement are now working again

Code: Select all

      $scoringDetail[] = sprintf($this->translations["flush_hand"], $points) . $handString . (($flushpts == 5) ? " " . self::cardValue($cutCard) : "");
but not this

Code: Select all

                $run_text = $this->translations["run" . $run_points . "_score_text"];
                self::notifyAllPlayers('score', $this->translations["run_score_info"], array (                
                    'player_id' => $player_id,                
                    'player_name' => self::getActivePlayerName(),
                    'points' => $run_points,
                    'score_text' => $run_text,
                    'i18n' => array('score_text')
                ));
I cannot spot or debug the difference, what is unique about this last piece of code
There is one other piece that will not translate but one problem at a time

Re: Translation on server side based on current player, not client?

Posted: 19 November 2020, 03:33
by quietmint
When you say it didn't work, last example, what do you mean? The variable score_text is not appearing in the notification message text at all. Are you trying to use score_text somehow yourself in JavaScript? It will always come as English. You'd need to translate it in JS if you want score_text in the current player language for some purpose to create element, etc. This auto translation stuff only works for the notification message text...

Re: Translation on server side based on current player, not client?

Posted: 19 November 2020, 11:00
by MikeIsHere
With no extra is
The pair text and 31 text get properly translated
The run text does not.
You can see this in studio also because the text for runs is not surrounded by <<>>. Everything else is, I cannot determine what is the difference about this one piece of code

Re: Translation on server side based on current player, not client?

Posted: 19 November 2020, 11:30
by Tisaac
I read your code and it confirms what quietmint and I are saying : you are not using the variable in the notification message !!!!
Please re-read my previous post about translation. This is 100% normal behavior.

Re: Translation on server side based on current player, not client?

Posted: 19 November 2020, 14:28
by MikeIsHere
I was typing up a response and I wanted to include an image but when I went to go run the game, it started working now for the Runs messages :!:

Thank you all for your help

Re: Translation on server side based on current player, not client?

Posted: 21 November 2020, 22:59
by MikeIsHere
Ok now I have a new problem I though each line of the scoring detail was getting translated because it was inside <<>>
but it is not

Here is the sample of the result
«Player MikeIsWorking1 has scored 5 points with their «Hand»:
Hand / Cut Card: J♣ 4♦ Q♦ A♠ / 6♣
Nobs for 1 J♣
15 for 3 A♠ 4♦ J♣
15 for 5 A♠ 4♦ Q♦ »
Here is some code on how it is being assembled
I guess the question is can I have a number of phrases translated and then compile them into one notification

Code: Select all

 $this->translations = = array(
"hand_total" => clienttranslate('Player ${player_name} has scored ${points} points with their ${hand}:<br/>${details}'),
);
...
$scoringDetail[] = sprintf($this->translations["nobs_hand"], $points) . self::cardValue(array_values($nobs)[0]);

$scoringDetail[] = sprintf($this->translations["fifteen_hand"], $points) . $cardString;
...
self::notifyAllPlayers('scoreHand', $this->translations["hand_total"], array(
            'player_id' => $player_id,
            'player_name' => $player_name,
            'points' => $points,
            'hand' => ($crib ? $this->translations["crib"] : $this->translations["hand"]),
            'details' => implode("<br/>", $scoringDetail),
            'i18n' => array('hand','details')
        ));

Re: Translation on server side based on current player, not client?

Posted: 21 November 2020, 23:56
by Tisaac
You should never use a concatenation in a translatable string !
Simply use sprintf everywhere to assemble the all message to make it works.