Clienttranslate and concatenation (implode)

Game development with Board Game Arena Studio
Post Reply
User avatar
cpasbanal
Posts: 35
Joined: 04 April 2020, 12:14

Clienttranslate and concatenation (implode)

Post 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 ?
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Clienttranslate and concatenation (implode)

Post 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.
User avatar
RavingWanderer
Posts: 83
Joined: 12 May 2020, 16:08

Re: Clienttranslate and concatenation (implode)

Post by RavingWanderer »

Another alternative is to use format_string_recursive in Javascript (link).
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Clienttranslate and concatenation (implode)

Post 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
User avatar
cpasbanal
Posts: 35
Joined: 04 April 2020, 12:14

Re: Clienttranslate and concatenation (implode)

Post 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!
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Clienttranslate and concatenation (implode)

Post 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.
Last edited by Tisaac on 01 April 2021, 08:53, edited 1 time in total.
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: Clienttranslate and concatenation (implode)

Post 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}'),
                            );
User avatar
cpasbanal
Posts: 35
Joined: 04 April 2020, 12:14

Re: Clienttranslate and concatenation (implode)

Post by cpasbanal »

smart, thanks tchobello!
Post Reply

Return to “Developers”