Problems with translation in notif logs with arguments

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

Problems with translation in notif logs with arguments

Post by Woodruff »

Hello,

I have troubles with translation inside the log, when the message is passed through a notification (notif_msg parameter). Enclosed arguments are not translated, even if all litteral strings are enclosed with clienttranslate().
Here's the simplest example of a string with argument that won't translate:

Code: Select all

self::notifyPlayer($player_id, 'log', clienttranslate('${You} have ${ressource_count} ${icon}.'), array(
    'You' => self::getColoredText(clienttranslate('You'), $player_id), /* 'You' word won't translate */
    'ressource_count' => $ressource_count,  /* just a number */
    'icon' => $icon /* just a span with a background-image */
));
The method getColoredText is defined like this:

Code: Select all

function getColoredText($text, $player_id) {
    $color = self::getPlayerColorFromId($player_id);
    return "<span style='font-weight: bold; color:#".$color.";'>".$text."</span>";
}
Here, all the string will appear translated in play, except the You that will remain You. This You is referenced in the translation string so the community could propose a translation for it.
Here the part of the string is passed to a function to be colored but there are other situations where these won't translate as well (a function to convert a code to the corresponding text, another to convert a number to its spelling, etc.).

Do you have any idea what I do wrong?

Thanks!

Tcheby
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: Problems with translation in notif logs with arguments

Post by DrKarotte »

Usually notifications with arguments to be translated need a "i18n" array handed over, in your example the line

'i18n' => array ('You'),

could do the trick?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Problems with translation in notif logs with arguments

Post by Victoria_La »

It won't get translated even with i18n because its bunch of non-static html. Just send "You have ${ressource_count} ${icon}"
without color. Or if you want fancy you can inject html on the client side. That is what I do with all my logs leaving php side html free.

Not posting here because its extensive example, but I added this to the wiki
http://en.doc.boardgamearena.com/BGA_St ... in_the_log
User avatar
Woodruff
Posts: 423
Joined: 08 March 2014, 00:53

Re: Problems with translation in notif logs with arguments

Post by Woodruff »

Thanks Victoria_La.
Nice tuto, that's will solve my issue.
One question: why do you use __("lang_mainsite", text) instead of _(text) for translatable strings in JS?
User avatar
Woodruff
Posts: 423
Joined: 08 March 2014, 00:53

Re: Problems with translation in notif logs with arguments

Post by Woodruff »

How would you do to do the same in action bar?
I have to inject card names like in Seasons.
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Problems with translation in notif logs with arguments

Post by Victoria_La »

Tchebychev wrote: One question: why do you use __("lang_mainsite", text) instead of _(text) for translatable strings in JS?
That just mean it will take translation from mainsite since"you" is already translated there,
you can do _("You") - that mean it will be added to your game strings,
and have to translated again for 30 languages
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Problems with translation in notif logs with arguments

Post by Victoria_La »

Tchebychev wrote:How would you do to do the same in action bar?
I have to inject card names like in Seasons.
You can use same technique, but if you just want text you can use just use args and i18n
I.e.
In states.php

Code: Select all

	"descriptionmyturn" => clienttranslate('${you} must do something with ${card_name}'),
        'args' => 'arg_playerTurn',
In ggg.game.php

Code: Select all

function  arg_playerTurn() {
    return ['card_name'=>clienttranslate("My Card"), 'i18n'=>['card_name'] ];
}
I did not test it but I think it should work
User avatar
Woodruff
Posts: 423
Joined: 08 March 2014, 00:53

Re: Problems with translation in notif logs with arguments

Post by Woodruff »

Right, I thought that i18n was for notifs only.
I will test that and report if that works.
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Problems with translation in notif logs with arguments

Post by Victoria_La »

Tchebychev wrote:Right, I thought that i18n was for notifs only.
I will test that and report if that works.
The description and its arguments are go though exact same function format_string_recursive, so it will use i18n and
if you override this function it will use your hacks (but it does add ${you} argument on its own case of state description)
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

Re: Problems with translation in notif logs with arguments

Post by quietmint »

Yes, this works automatically for the state description top white bar:
ss.png
ss.png (20.15 KiB) Viewed 3491 times
You can do same for action buttons by manually calling format_string_recursive() instead of dojo.substitute() when you add the button:

Code: Select all

var str = this.format_string_recursive(_('I block with my ${card_name}'), {
    card_name: name
});
this.addActionButton('button_block' + blocker, str, 'onBlock');
button.png
button.png (14.48 KiB) Viewed 3491 times
Post Reply

Return to “Developers”