Translation in the log

Game development with Board Game Arena Studio
User avatar
jonsmiley
Posts: 13
Joined: 11 November 2017, 01:05

Re: Translation in the log

Post by jonsmiley »

I thought I would be able to use clienttranslate() within sprintf the way the examples show using _() but that doesn't seem to be the case. Instead I am switching to the i18n argument method shown in the example but I'm not confident in what I am seeing in terms of translation results in studio.

Here's one of the simple code snippets. Based on the card_name example where it says to provide the original English string I didn't add clienttranslate around "moves to" and "stays in" and instead marked them as // NOI18N to address the warning in the project checker. For this one I could presumably just add both full log strings to be translated but there are more complex examples where that wouldn't work and I figured this simple example would help make sure I understand the concept correctly.

$guide_action = "moves to"; // NOI18N
if ($region == $section)
{
$guide_action = "stays in"; // NOI18N
}
$msg = clienttranslate('The ${guide_icon} ${guide_action} region ${region_icon}');
self::notifyAllPlayers( "placeGuide", $msg , array(
'i18n' => array ( 'guide_action' ),
'guide_action' => $guide_action,
'region' => $section,
'region_icon' => $section,
'guide_icon' => 'guide'
) );
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Translation in the log

Post by Tisaac »

That's not the good way to do it, you are still relying on structural aspect of english that might be impossible to translate in other languages.
You should simply do the following :

Code: Select all

$msg = ($region == $section)? clienttranslate('The ${guide_icon} moves to region ${region_icon}') :  clienttranslate('The ${guide_icon} stays in region ${region_icon}');
self::notifyAllPlayers( "placeGuide", $msg , array(
'region' => $section,
'region_icon' => $section,
'guide_icon' => 'guide'
) );
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

It would work, except that you have to use clienttranslate markers so that the strings are extracted for translation:

Code: Select all

$guide_action = clienttranslate("moves to");
if ($region == $section)
{
$guide_action = clienttranslate("stays in");
}
BUT by substituting the verb, you are assuming an English type syntax, which won't work in some languages.

So in this case, you should actually duplicate the entire sentence to make sure it can be properly translated in multiple languages.

Code: Select all

$msg = clienttranslate('The ${guide_icon} moves to region ${region_icon}');
if ($region == $section)
{
$msg = clienttranslate('The ${guide_icon} stays in region ${region_icon}');
}
self::notifyAllPlayers( "placeGuide", $msg , array(
'i18n' => array (),
'region' => $section,
'region_icon' => $section,
'guide_icon' => 'guide'
) );
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in the log

Post by Een »

Or what Tisaac said, I should have refreshed before posting ;)
User avatar
jonsmiley
Posts: 13
Joined: 11 November 2017, 01:05

Re: Translation in the log

Post by jonsmiley »

Thanks. I’ll try to apply this to my more complex cases and see if I can get those to work as well.

I think I was confused in the example where it said to use the original English in the argument which made me think I shouldn’t apply clienttranslate beforehand but I guess that may not apply here since it remains in English within PHP even if marked for clienttranslate. I also wasn’t sure if it was an issue to have clienttranslate strings embedded within each other—I.e. calling it on the partial phrases and then again on the entire message containing them.
Post Reply

Return to “Developers”