Nested arguments substitution

Game development with Board Game Arena Studio
Post Reply
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Nested arguments substitution

Post by Woodruff »

Hello!

Because for some complex situations it would be easier, I would like to do something like that (very simplified example):

Code: Select all

self::notifyPlayer('log', clienttranslate('${part_1} and ${part_2}', array(
	'part_1' => clienttranslate('${part_11} or ${part_12}'),
	'part_2' => clienttranslate('${part_21} or ${part_22}'),
	'part_11' => clienttranslate('card'),
	'part_12' => clienttranslate('cube'),
	'part_21' => clienttranslate('meeple'),
	'part_22' => clienttranslate('code'),
	'i18n' => array('part_1', 'part_2', 'part_11', 'part_12', 'part_21', 'part_22')
));
I expected the above example would send this string for translation:

Code: Select all

'card or cube and meeple or code'
(since it goes through the fonction format_string_recursive made me think it's... recursive).

But instead I get

Code: Select all

'{part_11} or {part_12} and {part_21} or {part_22}'
Is there any way to achieve a true recursive search on nested arguments? I would like to perform that too for gamestate description.

Thanks!

Tcheby
Last edited by Woodruff on 29 January 2018, 23:15, edited 1 time in total.
User avatar
Victoria_La
Posts: 619
Joined: 28 December 2015, 20:55

Re: Nested arguments substitution

Post by Victoria_La »

You are missing all the $ (dollars) is ${part_1}, does it actually work without them?
If you have recursive structure, the arguments of the other substructure have to be inside that array not outside, i.e.

Code: Select all

self::notifyPlayer('log', clienttranslate('${part_1} and ${part_2}'), array(
   'part_1' =>  array ('log'=> clienttranslate('${part_11} or ${part_12}')), 'args'=> array('part_11'=>...),
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Re: Nested arguments substitution

Post by Woodruff »

Hi Victoria_La,

Sorry for the missing dollars, I usually forget them until I test them code: without them it does not work indeed.
I have not tested that example; I update my first post.

Thanks for the trick. So if I understand well, in my example, format_string_recursive(log, args) would be called three times, for each couple of (log, args): first the two subarrays will be processed, then the global array made from the last two arguments of notifyPlayer.
Makes sense and much easier to understand that way, thanks!

Tcheby
Last edited by Woodruff on 29 January 2018, 23:22, edited 2 times in total.
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Re: Nested arguments substitution

Post by Woodruff »

I surmise then that the 'i18n' key is addable in each subarray like this:

Code: Select all

'part_1' =>  array ('log'=> clienttranslate('${part_11} or ${part_12}')), 'args'=> array('i18n' => array('part_11', 'part12'), 'part_11'=>...),
Is that so?
User avatar
Victoria_La
Posts: 619
Joined: 28 December 2015, 20:55

Re: Nested arguments substitution

Post by Victoria_La »

No if you have recursive structure you don't use i18n, its only used on string arguments, i.e. is ${part_11} is structure don't use i18n.
Also I hope you are using a better variable names or translators will pull their hair trying to translate it...

Code: Select all

$this->notifyAllPlayers('playerLog',clienttranslate('Game moves ${token_name_rec}'),
                  ['token_name_rec'=>['log'=>'${token_name} #${token_number}',
                                      'args'=> ['token_name'=>clienttranslate('Boo'), 'token_number'=>$number, 'i18n'=>['token_name'] ]
                                     ]
                  ]);
Tchebychev wrote:I surmise then that the 'i18n' key is addable in each subarray like this:

Code: Select all

'part_1' =>  array ('log'=> clienttranslate('${part_11} or ${part_12}')), 'args'=> array('i18n' => array('part_11', 'part12'), 'part_11'=>...),
Is that so?
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Re: Nested arguments substitution

Post by Woodruff »

Thanks for the clarification.
Don't worry, this example is entirely fake. I always try to use meaning names for translators (${cards}, ${action}, ${colors}...).
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Re: Nested arguments substitution

Post by Woodruff »

OK, I did that in practice, but I am still missing something since that does not translate (ie. the string appears in the translation page but its translated version is not applied in game.

Here's a simplified version of what I did:

Code: Select all

// In states.inc.php
    13 => array(
    "name" => "selectionMove",
    "descriptionmyturn" => clienttranslate('${card_name}: ${message_for_player}') . ' ', // The content is generated in argMyState
    "args" => "argMyState",
    ...
    ),

// In my_game.game.php
function argMyState() {
    $message_for_player = clienttranslate('Do ${you} want to do this?');
    $message_args_for_player = array('you' => 'you'); // This parts will be translated in the ovveridden version of format_string_recursive: it works
    
    return array(
        'card_name' => 'card_name', // Alright, this will be translated by format_string_recursive too, that part works
        
        'message_for_player' => array('i18n' => array('log'), 'log' => $message_for_player, 'args' => $message_args_for_player) // This part does not translate, unfortunately
    );
}
Do you have any clue on that?
User avatar
Victoria_La
Posts: 619
Joined: 28 December 2015, 20:55

Re: Nested arguments substitution

Post by Victoria_La »

Tchebychev wrote:OK, I did that in practice, but I am still missing something since that does not translate (ie. the string appears in the translation page but its translated version is not applied in game.

Here's a simplified version of what I did:

Code: Select all

// In states.inc.php
    13 => array(
    "name" => "selectionMove",
    "descriptionmyturn" => clienttranslate('${card_name}: ${message_for_player}') . ' ', // The content is generated in argMyState
    "args" => "argMyState",
    ...
    ),

// In my_game.game.php
function argMyState() {
    $message_for_player = clienttranslate('Do ${you} want to do this?');
    $message_args_for_player = array('you' => 'you'); // This parts will be translated in the ovveridden version of format_string_recursive: it works
    
    return array(
        'card_name' => 'card_name', // Alright, this will be translated by format_string_recursive too, that part works
        
        'message_for_player' => array('i18n' => array('log'), 'log' => $message_for_player, 'args' => $message_args_for_player) // This part does not translate, unfortunately
    );
}
Do you have any clue on that?
Ok you mark strings that need to be translated, log is exception because its translated by the framework, so you don't need to mark it.
Array i18n must be part of 'args', it does not count on the level you put it in. Since this is arguments and not part of recursive
structure you must call translation function on that arg in JS (as in another post about arg_ functions) before you use it in any UI element.
User avatar
Woodruff
Posts: 412
Joined: 08 March 2014, 00:53

Re: Nested arguments substitution

Post by Woodruff »

Thanks.
I'll try to fix that.
Post Reply

Return to “Developers”