Translation in template loop does not work

Game development with Board Game Arena Studio
Post Reply
User avatar
Volker78
Posts: 66
Joined: 29 April 2020, 21:37

Translation in template loop does not work

Post by Volker78 »

This is my code:

Code: Select all

	$this->page->begin_block("thurnandtaxis_thurnandtaxis", "player");

	...
		
		for ($i=0;$i<$playersCnt;$i++){
			$player = $players[$pointer];
			$this->page->insert_block("player", array(
				'PLAYER_ID' => $player['player_id'],
				'PLAYER_NAME' => $player['player_name'],
				'ROUTE_OF' => sprintf(self::_("Route of %s"), $player['player_name']),
				'SELF' => $pointer == $currentPlayerId ? 'self' : '',
			));

			$pointer = $nextPlayers[$pointer];
		};
The self::_("Route of %s") is translated (since many days), but the translation is not displayed. Does translation in loop-blocks not work?
User avatar
Volker78
Posts: 66
Joined: 29 April 2020, 21:37

Re: Translation in template loop does not work

Post by Volker78 »

Anyone?
User avatar
JumpMaybe
Posts: 41
Joined: 20 June 2019, 14:25

Re: Translation in template loop does not work

Post by JumpMaybe »

Hi Volker,

Do you see anything in the generated html?
The translation should be wrapped within <span class="to_translate"></span>.

If not can you post the "player" block from the .tpl?
User avatar
Volker78
Posts: 66
Joined: 29 April 2020, 21:37

Re: Translation in template loop does not work

Post by Volker78 »

it is wrapped with to-translate but still not translated, although the translation for that string is available
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

Re: Translation in template loop does not work

Post by quietmint »

I had a similar problem in Coup because I was manipulating the output of the view with JavaScript. Is it possible something like this is happening? In my case, I assumed the view was outputting already-translated text but in fact, the output was original English text with CSS markings for translation in the client side. I solved the problem by not using the view, instead building the whole HTML in JavaScript.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translation in template loop does not work

Post by Een »

I took the time to investigate this.

TL;DR you have to use a specific function gameview_str_replace( $search, $replace, $string ) instead of sprintf.

Full answer: we use a two step process for translations in templates in order to have them correctly translated in replays. The string is set first non translated inside a specific html marker; then the content of these markers is translated client side at runtime. Which allows the replay to be translated since it's client side only.

But if you use substitution on the server, then the text becomes different from the original (the substitution parameter is not there anymore). So it doesn't match the translation file and is not translated. The specific function gameview_str_replace adds some glue to make it work.

Please note that the recommended method is to manage setting translated text directly client side so that it works directly.

(I have added a "nota bene" on this under the tpl variable translation example in the studio translations documentation)
User avatar
Volker78
Posts: 66
Joined: 29 April 2020, 21:37

Re: Translation in template loop does not work

Post by Volker78 »

Thanks, that should answer my question
Post Reply

Return to “Developers”