Page 1 of 3

Double translation in log

Posted: 03 November 2020, 21:45
by Inaofr
I have a language key which seems to be translated twice when used in game log: 'gold', translated in the translation system to 'or' (French for gold) but then translated again as being the english or to 'ou' (French for or).
In the replay log the same log doesn't have the problem. See https://imgur.com/a/XHQ1vr6

The code of the notification:

Code: Select all

$item_name = $this->item_types[$item]['name'];
self::notifyAllPlayers('chooseItemNotify', clienttranslate('${player_name} takes ${item_name}'),
    array(
        'i18n' => array(
            'item_name'
        ),
        'player_id' => $player_id,
        'player_name' => $player_name,
        'item_name' => $item_name
    ));
Here $item_name is equal to 'gold'

$item_types is defined in another file:

Code: Select all

$this->item_types = array(
...
    E_Items::GOLD => array(
        'name' => 'gold',
        'nametr' => self::_('gold'),
        'nametrcl' => clienttranslate('gold'),
        'diviser' => 6
    ),
...
Is there anything wrong in my code? I tend to think it is a framework bug.

Please note that there is not even a translation for 'or' in the translation system of the game (which is in alpha).

Re: Double translation in log

Posted: 03 November 2020, 23:13
by Victoria_La
Nothing obviously wrong except not sure why you going this;
'name' => 'gold',
'nametrcl' => clienttranslate('gold'),

This is redundant. Function clienttranslate is no-op on php side it only used as marker so this would have been suffifient
'name' => clienttranslate('gold'),

What are you doing with nametrcl and nametr though?
You probably double translating on client side
FYI you can also use [] for arrays, i.e. 'i18n' => [ 'item_name' ],

Re: Double translation in log

Posted: 03 November 2020, 23:58
by Inaofr
I'm doing nothing on client side, it is not listening to notification 'chooseItemNotify'.
The name, nametr and nametrcl are legacy code, I don't know why it was done this way (I'm not the original coder, I'm coding an expansion of a game which as fas as I know is among the oldest on BGA).
The nametr is used in some sprintf like:

Code: Select all

$bonus = sprintf(self::_('roll 2 dices and produce %s'), $this->item_types[$item]['nametrp']);
The nametrcl is used nowhere in the alpha version of the game (with the new expansion), and at only one place in the version currently running as main version on BGA:

Code: Select all

self::notifyAllPlayers('sendPlayerItem', $notif, array(
    'type' => $itemName, 'player_id' => $playerId, "player_name" => $playerName,
    'source' => $source, 'nbr' => $qt, 'item_name' => $this->item_types[$item]['nametrcl']
));

In fact in the alpha I have rewritten this the way described in the framework doc:

Code: Select all

self::notifyAllPlayers('sendPlayerItem', $notif,
    array(
        "i18n" => array(
            'item_name'
        ),
        'item' => $item,
        'player_id' => $playerId,
        "player_name" => $playerName,
        'source' => $source,
        'nbr' => $qt,
        'item_name' => $this->item_types[$item]['name']
    ));
So know I guess that having 'gold' marked as having to be translated on client side is the root cause of the double translation: I suppose that when the notification with i18n is received with 'item_name' having the value 'gold', the marking through clienttranslate cause a first translation of 'gold' to 'or', and then the i18n translation translate 'or' to 'ou' (it might be the reverse order but it is less probable).

I'm going to test that, thanks for helping me out.

Re: Double translation in log

Posted: 04 November 2020, 00:12
by Inaofr
I have removed all the unused clienttranslate, that's doesn't change anything, double translation still happens.
But I think the self::_('gold') might be faulty, as it is written in code which is executed at initialization of the game, not when a player is calling a method through ajax. As far as I have understood, self::_() is meant to translate when executed from a call originated from ajax as it is supposed to use the language of the player calling it.
So I think I should remove all the nametr too, and replace them by a call to self::_ in the code executed from ajax.

Edit: the BGA doc is giving an example of self::_ in material.inc.php, which is the place where I have mines, so they are probably OK.

Code: Select all

// In material.inc.php, $this->energies[n]['nametr'] has been created with the self::_() method. Now we can do this:
throw new BgaUserException( self::_("To execute this action you need more: ").' '.$this->energies[$resource_id]['nametr'] );

Re: Double translation in log

Posted: 04 November 2020, 01:18
by Victoria_La
self::_ you basically use in exception because they are not send via notification to all clients

This seems definitely wrong
self::notifyAllPlayers('sendPlayerItem', $notif, array(
'type' => $itemName, 'player_id' => $playerId, "player_name" => $playerName,
'source' => $source, 'nbr' => $qt, 'item_name' => $this->item_types[$item]['nametrcl']
));

Becuase name and nametrcl is the same stirng on php, so show this properly it must be translating this on client side some-how
What is this game?

Re: Double translation in log

Posted: 04 November 2020, 07:25
by Inaofr
It is Stone Age.
The code you quote is the code of the current version, it is not anymore the code of the alpha version, so it is not the root of the issue.

I just have checked that the issue is not in the current version. But in the current version 'gold' is translated to 'Or' instead of 'or'. So just for test I changed 'or' to 'Or' in the alpha version translation system, I now have to wait tomorrow for the translation system to update.

Re: Double translation in log

Posted: 04 November 2020, 08:58
by Een
If there is a double translation, you should be able to see it using the "display dummy translations" tool on the studio manage page.

Re: Double translation in log

Posted: 04 November 2020, 11:48
by Inaofr
I have this:
«Inaofr1 produced 2 «gold»»
Is it normal consequence of I18n) or not?

Re: Double translation in log

Posted: 05 November 2020, 11:33
by Een
Yes, that's exactly what's expected: the full string is translated once (one set of brackets surrounding it) and the substitution parameter marked to be translated with i18n is translated once too (one set of brackets around it).

So all seems good. If you have a live example to check, can you look at the html markup of a log with the issue you described?

Re: Double translation in log

Posted: 05 November 2020, 22:27
by Inaofr
Here it is:

Code: Select all

<div class="roundedbox"><!--PNS--><span class="playername"><!--PNS--><span class="playername" style="color:#0000ff;">Inaofr</span><!--PNE--></span><!--PNE--> prend ou</div>
This from the log of game 121219248 at move 23.

Please note there is no "ou" word in the translation page of Stone Age: The Expansion (https://boardgamearena.com/translation? ... =ou&page=2).

I also just have started a new game in hot seat for test and grabbed a gold, now that I have changed in the translation system "or" to "Or", the double translation is not occurring anymore:

Code: Select all

<div class="roundedbox"><!--PNS--><span class="playername"><!--PNS--><span class="playername" style="color:#ff0000;">moi</span><!--PNE--></span><!--PNE--> prend Or</div>
I suspect this issue is also in the main Stone Age game and was "fixed" a long time ago by replacing or with Or.