Page 1 of 1
Nested arguments substitution
Posted: 28 January 2018, 16:44
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:
(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
Re: Nested arguments substitution
Posted: 28 January 2018, 20:33
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'=>...),
Re: Nested arguments substitution
Posted: 29 January 2018, 23:14
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
Re: Nested arguments substitution
Posted: 29 January 2018, 23:20
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?
Re: Nested arguments substitution
Posted: 30 January 2018, 01:48
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?
Re: Nested arguments substitution
Posted: 03 February 2018, 17:22
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}...).
Re: Nested arguments substitution
Posted: 18 March 2018, 02:01
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?
Re: Nested arguments substitution
Posted: 19 March 2018, 03:41
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.
Re: Nested arguments substitution
Posted: 29 March 2018, 18:46
by Woodruff
Thanks.
I'll try to fix that.