Double translation in log

Game development with Board Game Arena Studio
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Double translation in log

Post by Een »

Thanks for the snippets, I wanted to check that there was no special translation markup around the double translation (there isn't). Indeed this is strange, something to investigate when possible.
User avatar
Inaofr
Posts: 142
Joined: 26 March 2020, 22:26

Re: Double translation in log

Post by Inaofr »

I have added a log on the notification suffering double translation, here is the result:

Code: Select all

notifChooseItemNotify 
	{…}
		​args: {…}
			i18n: Array [ "item_name" ]
​​			item_name: "ou"
			​​player_id: "85832506"
			​​player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">Inaofr</span><!--PNE--></span><!--PNE-->"
​​			<prototype>: Object { … }
		​bIsTableMsg: true
		channelorig: "/table/t122075886"
​		gamenameorig: "stoneageext"
		​h: "8d7d61"
		​log: "${player_name} takes ${item_name}"
		​move_id: 44
		​table_id: "122075886"
		​time: 1604700908
		​type: "chooseItemNotify"
		​uid: "5fa5caec61a2b"
		​<prototype>: Object { … }
stoneageext.js:1:68593
notifChooseItemNotify 
	{…}
		​args: {…}
			​​i18n: Array [ "item_name" ]
			​​item_name: "ou"
			​​player_id: "85832506"
			​​player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">Inaofr</span><!--PNE--></span><!--PNE-->"
​​			<prototype>: Object { … }
		​bIsTableMsg: true
		​channelorig: "/table/t122075886"
		​gamenameorig: "stoneageext"
		​h: "8d7d61"
		​log: "${player_name} takes ${item_name}"
		​move_id: 44
		​table_id: "122075886"
		​time: 1604700908
		​type: "chooseItemNotify"
		​uid: "5fa5caec61a2b"
		​<prototype>: Object { … }
stoneageext.js:1:68593
The item_name is already translated twice, and the notification is duplicated (received two times, with same uid).
I also have added a debug log on server side on the arguments passed with the notification, but I didn't succeed to retrieve it from the main BGA server, using the studio control panel (⇨ Load bug report state into this table save slot #1).
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Double translation in log

Post by Een »

Then it would mean that this occurs on the server side.

Please note that it's needed to have a clienttranslate() for the item name in the materials.inc.php (so that it's marked in the translation system as a string used on the client side), and that 'nametr' should be used in the context of server side translation, and 'nametrcl' should be used in the context of client side translation (in principle; in practice as clienttranslate is a transparent function it should be the same as 'name' for practical purposes).

Could you test with a different parameter name ('myitemname' instead of 'item_name' for example) and using nametrcl to get the value? (to rule out the case of some rule applying to some parameters by name?)
User avatar
Inaofr
Posts: 142
Joined: 26 March 2020, 22:26

Re: Double translation in log

Post by Inaofr »

Same result:

Code: Select all

notifChooseItemNotify 
{…}
​args: {…}
​​i18n: Array [ "myitemname" ]
​​myitemname: "ou"
​​player_id: "84634030"
​​player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">moi</span><!--PNE--></span><!--PNE-->"
​​<prototype>: Object { … }
​bIsTableMsg: true
​channelorig: "/table/t122283066"
​gamenameorig: "stoneageext"
​h: "bb1445"
​log: "${player_name} takes ${myitemname}"
​move_id: 30
​table_id: "122283066"
​time: 1604777114
​type: "chooseItemNotify"
​uid: "5fa6f49a6d4db"
​<prototype>: Object { … }
stoneageext.js:1:68593

notifChooseItemNotify 
{…}
​args: {…}
​​i18n: Array [ "myitemname" ]
​​myitemname: "ou"
​​player_id: "84634030"
​​player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">moi</span><!--PNE--></span><!--PNE-->"
​​<prototype>: Object { … }
​bIsTableMsg: true
​channelorig: "/table/t122283066"
​gamenameorig: "stoneageext"
​h: "bb1445"
​log: "${player_name} takes ${myitemname}"
​move_id: 30
​table_id: "122283066"
​time: 1604777114
​type: "chooseItemNotify"
​uid: "5fa6f49a6d4db"
​<prototype>: Object { … }
The modified code (I have added an error trace to be able to retrieve it):

Code: Select all

            $item_name = $this->item_types[$item]['nametrcl'];
            self::error('chooseItemNotify item name: '.$item_name);
            self::notifyAllPlayers('chooseItemNotify', clienttranslate('${player_name} takes ${myitemname}'),
                array(
                    'i18n' => array(
                        'myitemname'
                    ),
                    'player_id' => $player_id,
                    'player_name' => $player_name,
                    'myitemname' => $item_name
                ));
The error trace result:

Code: Select all

07/11 20:25:14 [error] [T122283066] [84634030/_hotseat01] chooseItemNotify item name: gold
By the way, the studio doc does not say explicitly that clienttranslate should be used for i18n arguments (http://en.doc.boardgamearena.com/Transl ... _.28PHP.29). It can be deduced from the text written above, but it is not obvious.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Double translation in log

Post by Tisaac »

Inaofr wrote: 07 November 2020, 20:44 By the way, the studio doc does not say explicitly that clienttranslate should be used for i18n arguments (http://en.doc.boardgamearena.com/Transl ... _.28PHP.29). It can be deduced from the text written above, but it is not obvious.
Well, if you understand the basic of the translation system, it's quite obvious (clienttranslate is just a marker that a script is looking for when parsing your files to see what are the translatable strings), but feel free to edit the doc to add it, it's a wiki after all ;)
User avatar
Inaofr
Posts: 142
Joined: 26 March 2020, 22:26

Re: Double translation in log

Post by Inaofr »

In fact, as far as I understand, the string should be marked somewhere by either clienttranslate, or self::_ or even _() if it is also translated on client side. In my case, the raw material names are already translated on server side with self::_ (as their may be returned in result of same player action) and on client side with _(), so adding a clienttranslate version is probably useless.
In fact, I wonder if my double translation issue is linked to the fact that these strings are marked twice for translation, one time on server side and one time on client side.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Double translation in log

Post by Tisaac »

Inaofr wrote: 08 November 2020, 10:55 In fact, as far as I understand, the string should be marked somewhere by either clienttranslate, or self::_ or even _() if it is also translated on client side. In my case, the raw material names are already translated on server side with self::_ (as their may be returned in result of same player action) and on client side with _(), so adding a clienttranslate version is probably useless.
In fact, I wonder if my double translation issue is linked to the fact that these strings are marked twice for translation, one time on server side and one time on client side.
No that's not exactly how it works : using _ on client side is both a marker AND calling the translation itself. This means that if you send stuff marked with client translate on backend and try to display them on frontend using inner HTML for instance, it wont work. You will need to call _() on the string unless special cases such as notifications for instance.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Double translation in log

Post by Een »

Sorry if it's not clear, indeed don't hesitate to update the wiki page if needed to clarify.
_() should never be used in php code for games as it will match the mainsite translation and not the game translations
_() should be used in javascript code for strings to translate client side (and there are no other strings in javascript so it should be the only case theree)
self::_() in php code marks the game strings to be translated on the server side (and applies the translation at runtime as mentioned by Tisaac), so strings marked only with self::_() will be only included in the server localization files (gettext .po/.mo files) to translate server side
clienttranslate() in php code marks the strings to be translated on the client side, so strings marked only with clienttranslate will be only included in the client localization files (js) to translate client side

Coming back to the issue of double translation, can you make a test also without the i18n? This would help narrow down where to look for this issue.
User avatar
Inaofr
Posts: 142
Joined: 26 March 2020, 22:26

Re: Double translation in log

Post by Inaofr »

Thanks for the clarification.

For this notification, nothing is translated anymore, the in game log is now showing "moi takes gold" (I was expecting "moi prend gold", moi is the name I chosed for the hotseat player). The javascript notification log:

Code: Select all

notifChooseItemNotify 
{…}
​args: Object { player_id: 84634030, player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">moi</span><!--PNE--></span><!--PNE-->", myitemname: "gold" }
​bIsTableMsg: true
​channelorig: "/table/t122474395"
​gamenameorig: "stoneageext"
​log: "${player_name} takes ${myitemname}"
​move_id: 27
​table_id: "122474395"
​time: 1604841677
​type: "chooseItemNotify"
​uid: "5fa7f0cd73420"
​<prototype>: Object { … }
stoneageext.js:1:68593
notifChooseItemNotify 
{…}
​args: Object { player_id: 84634030, player_name: "<!--PNS--><span class=\"playername\"><!--PNS--><span class=\"playername\" style=\"color:#0000ff;\">moi</span><!--PNE--></span><!--PNE-->", myitemname: "gold" }
​bIsTableMsg: true
​channelorig: "/table/t122474395"
​gamenameorig: "stoneageext"
​log: "${player_name} takes ${myitemname}"
​move_id: 27
​table_id: "122474395"
​time: 1604841677
​type: "chooseItemNotify"
​uid: "5fa7f0cd73420"
​<prototype>: Object { … }
stoneageext.js:1:68593
Notification is still received twice (maybe because of hotseat).
The notification code without i18n:

Code: Select all

            self::notifyAllPlayers('chooseItemNotify', clienttranslate('${player_name} takes ${myitemname}'),
                array(
                    'player_id' => $player_id,
                    'player_name' => $player_name,
                    'myitemname' => $item_name
                ));
Last edited by Inaofr on 08 November 2020, 17:45, edited 2 times in total.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Double translation in log

Post by Een »

Stranger and stranger. I'll make some tests when I can find the time.
Post Reply

Return to “Developers”