Page 1 of 1

Clienttranslate and concatenation (implode)

Posted: 31 March 2021, 20:05
by cpasbanal
Hi,

I know we shouldn't concatenate

Code: Select all

clienttranslate()
translations as described here (https://en.doc.boardgamearena.com/Translations) because it might alter the way the string would be translated in each language.

Yet, in my case in Harbour, i want to log all the ressources the player just got (can be 1, 2, 3 or 4) and I would like to do this:

------

My variable is dynamically set with something like (wood, stone, livestock, fish and their values depends of course of the player action) :

Code: Select all

$goods_displayed = ['1 wood', '2 stone']

Note that stone and wood do have translations and I can wrap them within a clienttranslate()

And then use:

Code: Select all

self::notifyAllPlayers( "gainGoods", clienttranslate( '${player_name} gets ${goods_displayed} from ${building_name}' ), array(
                'i18n' => array('goods_displayed'),
                'player_id' => $player_id,
                'player_name' => $player['name'],
                'goods_displayed' => implode(', ', $goods_displayed),
                'building_name' => $building_name,
            )
        ) );
But it doesn't work because notifyAllPlayers i18n parameter expect a perfect non-concatenated clienttranslate string.

Do any of you have a good idea on how to implement this case nicely ?

Re: Clienttranslate and concatenation (implode)

Posted: 31 March 2021, 20:27
by Tisaac
cpasbanal wrote: 31 March 2021, 20:05 Hi,

I know we shouldn't concatenate

Code: Select all

clienttranslate()
translations as described here (https://en.doc.boardgamearena.com/Translations) because it might alter the way the string would be translated in each language.

Yet, in my case in Harbour, i want to log all the ressources the player just got (can be 1, 2, 3 or 4) and I would like to do this:

------

My variable is dynamically set with something like (wood, stone, livestock, fish and their values depends of course of the player action) :

Code: Select all

$goods_displayed = ['1 wood', '2 stone']

Note that stone and wood do have translations and I can wrap them within a clienttranslate()

And then use:

Code: Select all

self::notifyAllPlayers( "gainGoods", clienttranslate( '${player_name} gets ${goods_displayed} from ${building_name}' ), array(
                'i18n' => array('goods_displayed'),
                'player_id' => $player_id,
                'player_name' => $player['name'],
                'goods_displayed' => implode(', ', $goods_displayed),
                'building_name' => $building_name,
            )
        ) );
But it doesn't work because notifyAllPlayers i18n parameter expect a perfect non-concatenated clienttranslate string.

Do any of you have a good idea on how to implement this case nicely ?
As sais in the doc above, i would go with 4 different messages for the four different cases.

Re: Clienttranslate and concatenation (implode)

Posted: 31 March 2021, 20:45
by RavingWanderer
Another alternative is to use format_string_recursive in Javascript (link).

Re: Clienttranslate and concatenation (implode)

Posted: 31 March 2021, 20:49
by Een
For displaying resources like this, I would actually advise to use some icons rather than translated text to make the log nicer, see for example CuBirds on the studio, or the documentation https://en.doc.boardgamearena.com/BGA_S ... in_the_log

Re: Clienttranslate and concatenation (implode)

Posted: 01 April 2021, 07:04
by cpasbanal
Thank your for your quick answers:

- 4 messages --> actually i can have 16 different messages (player can gain wood only, or wood and stone or wood and stone and fish, etc.), it can be acceptable but not very fun to translate (and I may have another notifyAllPlayers)

- using format_string_recursive --> I considered that too but it won't work for turn-based game since it displays the stored log

- thanks Een for you kind remember about using icons _from server_ (since I wanted to avoid format_string_recursive, I'll test that, I hope it won't overload too much the logs and I have to check if the design renders well eventually

- for the record, I also considered 4 variables $wood_gained, $stone_gained, etc. that I would concatenate in the $message log, string would be empty if player gained none. The caveat is I would have an extra comma in the end of my 'contatenated' string: "cpasbanal gets 1 wood, 1 stone, from The Wharfs"

I'll compare those methods to see which renders the best.

Thanks a lot to the three of you for your help!

Re: Clienttranslate and concatenation (implode)

Posted: 01 April 2021, 07:49
by Tisaac
cpasbanal wrote: 01 April 2021, 07:04 Thank your for your quick answers:

- 4 messages --> actually i can have 16 different messages (player can gain wood only, or wood and stone or wood and stone and fish, etc.), it can be acceptable but not very fun to translate (and I may have another notifyAllPlayers)
No no, only 4 messages, put the name of the ressource in a variable, as described below by tchobello.

Re: Clienttranslate and concatenation (implode)

Posted: 01 April 2021, 08:07
by tchobello
hi, I have something like this in Dungeon Twister :

Code: Select all

        $i = 0;
        foreach( $token_to_place as $token_id => $token_type )
        {
            $items['item'.$i] = Array(
                'log' => clienttranslate('${tokenName}'), 
                'args' => Array('tokenName' => $this->token_types[ $token_type ]['name'], 
                                'i18n' => Array('tokenName')
                                )
                );
            $items['i18n'][] = 'item'.$i;
            $i++;
        }

        // Notify
        self::notifyAllPlayers( "roomDiscovered", clienttranslate( '${player_name} reveals room with: ${items_list}' ), array(
            'player_id' => $player_id,
            'player_name' => self::getActivePlayerName(),
            'tile_infos' => $tile,
            'tile_id' => $tile_id,
            'tile_type' => $tile['type'],
            'orientation' => $tile['orientation'],
            'items_list' => array(
                'log' => $this->itemListLogs[$i],
                'args' => $items 
                ),
            'i18n' => array( 'items_list' )
            )
        );

and this in Material :

Code: Select all

$this->itemListLogs = Array('', clienttranslate('${item0}'), clienttranslate('${item0} and ${item1}'),
                            clienttranslate('${item0}, ${item1} and ${item2}'),
                            clienttranslate('${item0}, ${item1}, ${item2} and ${item3}'),
                            clienttranslate('${item0}, ${item1}, ${item2}, ${item3} and ${item4}'),
                            clienttranslate('${item0}, ${item1}, ${item2}, ${item3}, ${item4} and ${item5}'),
                            clienttranslate('${item0}, ${item1}, ${item2}, ${item3}, ${item4}, ${item5} and ${item6}'),
                            clienttranslate('${item0}, ${item1}, ${item2}, ${item3}, ${item4}, ${item5}, ${item6} and ${item7}'),
                            );

Re: Clienttranslate and concatenation (implode)

Posted: 01 April 2021, 08:28
by cpasbanal
smart, thanks tchobello!