Page 1 of 1

clienttranslate does not work in php

Posted: 11 October 2024, 22:19
by BaronBeule
I need no generate complex text by concatenation, but nothing works. I tried
sprintf
str_replace
or this:

Code: Select all

self::notifyAllPlayers( "notifLog", clienttranslate( '${player_name} earns 1 x') . ' ' . wood . ' '. clienttranslate( 'Wood.') , array(...
but it only works, if I use it in a static way without any additional code:

Code: Select all

clienttranslate( 'bla bla')
Any help plz, thx

Re: clienttranslate does not work in php

Posted: 12 October 2024, 00:53
by robinzig
The answers are all here https://boardgamearena.com/doc/Translations

Basically, concatentation doesn't work in clienttranslate. It's not clear to me from your example what you're trying to do (what is the `wood` that you're trying to concatenate between the clienttranslate calls? It doesn't look like a PHP variable as it doesn't start with a $) - but it should be achievable in one of the ways suggestesd in that doc page, either sprintf or including ${some_variable} inside a single string passed to clienttranslate and with that then in the i18n array of the notification if it needs translation.

You say you tried some of these things, but without saying specifically what you tried we can't know what you did wrong.

Re: clienttranslate does not work in php

Posted: 12 October 2024, 05:30
by ufm
robinzig wrote: 12 October 2024, 00:53 The answers are all here https://boardgamearena.com/doc/Translations
FIFY: https://en.doc.boardgamearena.com/Translations

Check this link as well: https://bga-devs.github.io/blog/posts/t ... s-summary/
This link is at the end of the first document, but the recursion is one of the most important aspects in the BGA translation.

Re: clienttranslate does not work in php

Posted: 12 October 2024, 08:33
by tchobello
Hello,
if you want to write something like 'player_name earns 3 Wood' and 3 is the variable $wood (don't forget the $) :

Code: Select all

self::notifyAllPlayers( "notifLog", clienttranslate( '${player_name} earns ${wood} Wood'), [...] ) ;
If you follow the links and learn more about format_string_recursive, you'll be able to replace Wood by an icon.

Re: clienttranslate does not work in php

Posted: 12 October 2024, 11:53
by BaronBeule
thanks all for your quick reply, and yes 'wood' is a typo, it is a php variable and should be $wood ;-)