Translation in the log

Game development with Board Game Arena Studio
User avatar
Emanuele Ornella
Posts: 23
Joined: 09 January 2016, 19:07

Translation in the log

Post by Emanuele Ornella »

Ok, I have another small issue on translation that I cannot understand.

I am sending a notification with the only word "takes" and some pictures. See attachment.

I was following something similar to what is described for Terra Mystica somewhere in the docs.
I know I should not use html in the notifications, but I have only 1 word to translate and the rest are 1, 2 or 3 pictures.

The issue is that the word is not translated :-( so I am missing something.

This is the code I am using:

Code: Select all

$collects_translated = self::_('takes');
I also tried with (not sure what would be the difference) with the same effect: no translation.

Code: Select all

$collects_translated = clienttranslate('takes');
I am then using that variable inside another one:

Code: Select all

$message_to_send = '<div>${player_name} '.$collects_translated.' '.$notificationtoall.'</div>';
and then finally send that string to all players:

Code: Select all

self::notifyAllPlayers( "tilesPlayednotification", 
   							 $message_to_send,
								array(
										'player_id' => $player_id,
										'player_name' => self::getActivePlayerName(),
										'tile_ids' => $cards,
										'player_name' => self::getActivePlayerName()
									) 
							);
Previously I was filling this variable inside a foreach loop with some divs:

Code: Select all

$notificationtoall .= "<div class='cardspritesthumb cardthumb_{$mytile['tile_character']}_{$mytile['tile_face']}'></div> ";
The result in the log is:

Code: Select all

<div><!--PNS--><span class="playername"><!--PNS--><span class="playername" style="color:#ff0000;">Emanuele Ornella</span><!--PNE--></span><!--PNE--> takes <div class="cardspritesthumb cardthumb_1_normal"></div> <div class="cardspritesthumb cardthumb_1_normal"></div> </div>
which, as you can see in the screenshot, works perfectly for the images, but the text "takes" is not translated, even if translation is provided.


Also: another question. In studio.boargamearena.com seems there is only English as language. So I cannot effectively test other solutions if not deploying a new version in production. Which is not effective if I am not sure about the solution.. I do not like to try in production just because I do not know if the change is a real solution! So is there any way I can test this in studio.boargamearena.com ? I mean the translations of the text?
This would be also good to test if I forgot some translation before deploying to production.

Thanks,
Ema
Attachments
takes translation.jpg
takes translation.jpg (23.68 KiB) Viewed 3490 times
takes log.jpg
takes log.jpg (9.83 KiB) Viewed 3490 times
User avatar
Lymon Flowers
Posts: 195
Joined: 01 April 2020, 21:14

Re: Translation in the log

Post by Lymon Flowers »

The whole notification string is passed in the javascript to the translation function, so with your HTML and stuff. I would advise that you do something similar that the following intp your code : http://en.doc.boardgamearena.com/BGA_St ... in_the_log

Regarding translation, yes, for now the way to do this is to test in production. Not too good but that is the only possibility for now. I think the admins are working on it.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

Code: Select all

self::_('takes');
Translates the string on the server side (so if you do this, then pass the result to the client through a notification, it will be in the language of the player who triggered the request to the server for all other players.

Code: Select all

clienttranslate('takes');
Is just a marker so that we know that this string will be translated on the client side. It does nothing by itself except make the string available in the translation system.

To be correctly translated on the clientside, the string received must be exactly the same as the one marked with clienttranslate. So the string sent through the notification must not be created ad-hoc with concatenation.

In the Terra Mystica example in the doc, there is a stable string that will get translated:

Code: Select all

$message = clienttranslate('${player_name} gets ${power_income} via Structures');
And ${power_income} is substituted with some icon content placed in the notification:

Code: Select all

self::notifyAllPlayers( "powerViaStructures", $message, array(
			'i18n' => array( ),
			'player_id' => $player_id,
			'player_name' => self::getUniqueValueFromDb( "SELECT player_name FROM player WHERE player_id = $player_id" ),
			'power_tokens' => $power_tokens,
			'vp_price' => self::getLogsVPAmount($price),
			'power_income' => self::getLogsPowerAmount($power_income),
			'newScore' => self::getUniqueValueFromDb( "SELECT player_score FROM player WHERE player_id = $player_id" ),
			'counters' => $this->getGameCounters(null),
		) );
Hope it helps :)
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

bdrieu wrote: 19 June 2020, 14:40 Regarding translation, yes, for now the way to do this is to test in production. Not too good but that is the only possibility for now. I think the admins are working on it.
On my list indeed... When is another matter :)
User avatar
Emanuele Ornella
Posts: 23
Joined: 09 January 2016, 19:07

Re: Translation in the log

Post by Emanuele Ornella »

Ok,
I am still a bit confused...
So if

Code: Select all

self::_('takes');
is translating on the player's locale for all other players, this is not a good solution.. not sure why this was ever implemented?
Indeed I am now seeing this this in Tea Time because I have used this. I can see the other players' translation in their languages... Not nice indeed.

Now if

Code: Select all

clienttranslate('takes');
does nothing other than reserving an entry in the translation tool, do I really need to override the "format_string_recursive" ?
Let's forget a moment about having html and images in the notification string.
Let's suppose I have a straightforward:

Code: Select all


$message_to_send = clienttranslate('takes');

self::notifyAllPlayers( "tilesPlayednotification", 
   							 $message_to_send,
array(
	'player_id' => $player_id,
	'player_name' => self::getActivePlayerName(),
	'tile_ids' => $cards,
	'player_name' => self::getActivePlayerName()
) 
);
How is the "takes" string translated on the client side? And will it be translated?
Because on the javascript I do not have anything like _("takes").
So how is this "magically" translated?

Maybe I am not understanding because I did not understand the format_string_recursive function... and honestly I did not understand what I have to change on the override as indicated here http://en.doc.boardgamearena.com/BGA_St ... in_the_log
This is even more complicated by the fact I cannot test in studio.boardgamearena.com so I cannot "figure out myself"...

:(
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: Translation in the log

Post by DrKarotte »

The translation with self::_(....) is there for error messages, as far as I understand. These are created on server side, so it is good to have the language of the current player.

I have once checked the "images in notifications" section but given up. At first it seems to be fine, but than I realized that I probably have to rewrite the whole client side code, as there are no "classic" notifications anymore.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

Emanuele Ornella wrote: 20 June 2020, 10:18 So if

Code : Tout sélectionner

self::_('takes');

is translating on the player's locale for all other players, this is not a good solution.. not sure why this was ever implemented?
I checked the documentation and the 3 cases where it's useful are properly documented :D
http://en.doc.boardgamearena.com/Transl ... _.28PHP.29

But yes, for notifications it's always clienttranslate that should be used, and composing strings should always be done with substitution variables and not using concatenation.
Emanuele Ornella wrote: 20 June 2020, 10:18 Let's suppose I have a straightforward:

Code : Tout sélectionner


$message_to_send = clienttranslate('takes');

self::notifyAllPlayers( "tilesPlayednotification",
$message_to_send,
array(
'player_id' => $player_id,
'player_name' => self::getActivePlayerName(),
'tile_ids' => $cards,
'player_name' => self::getActivePlayerName()
)
);

How is the "takes" string translated on the client side? And will it be translated?
Because on the javascript I do not have anything like _("takes").
So how is this "magically" translated?
The framework "magically" does it for you :)
_() is automatically applied to the "message" parameter of the notification when it's received on the client side (with the format_string_recursive function to be able to take multiple levels of parameters into account, but most of the time you don't care about recursion since most messages are simple)
Emanuele Ornella wrote: 20 June 2020, 10:18 Maybe I am not understanding because I did not understand the format_string_recursive function... and honestly I did not understand what I have to change on the override as indicated here http://en.doc.boardgamearena.com/BGA_St ... in_the_log
The method from Victoria_La is a little complex indeed. She is a better developer than I am :)
My recommendation is to use the simpler method I have documented as an alternative way to have game logs with icons:
http://en.doc.boardgamearena.com/BGA_St ... native_way

Maybe I should make it the main entry point on this since it's more simple.
User avatar
jonsmiley
Posts: 13
Joined: 11 November 2017, 01:05

Re: Translation in the log

Post by jonsmiley »

I seem to have run into this same bug in my adaptation of Nanga Parbat. I mistakenly used _() for a couple of partial phrases in the log notifications (exactly like the ‘takes’ example above) and players pointed out they were seeing those few words in their opponent’s language.

I switched _() to clienttanslate() and thought that solved it but apparently now people are only seeing those words in English even when the translation exists in their language (and has now for weeks). I turned the translation identifiers on in Studio when I tested the change, committed, built, and deployed but is there anything else I should have needed to do to get those string flagged for translation?

The strings didn’t change from the earlier versions (just whether they were inside _() or clienttranslate()) so I can see that many of the translations were entered before I made that change. I did make the error of concatenating the phrases instead of using substitution as pointed about above and in the translation documentation but could that cause the clienttranslate() of the partial phrase to fail?
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

jonsmiley wrote: 22 October 2020, 05:18 I did make the error of concatenating the phrases instead of using substitution as pointed about above and in the translation documentation but could that cause the clienttranslate() of the partial phrase to fail?
Yes, most likely. Please post an example to be sure, but in general, you should use substitution, not concatenation: concatenation does not work with internationalization as it presupposes some linguistic structures, and on the technical side it also breaks translation in most cases.
User avatar
jonsmiley
Posts: 13
Joined: 11 November 2017, 01:05

Re: Translation in the log

Post by jonsmiley »

Thanks, I will fix the concatenation issue either way then and see if the problem still exists and post an example if it does.
Post Reply

Return to “Developers”