Page 1 of 1

Translation in template loop does not work

Posted: 23 August 2020, 20:07
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?

Re: Translation in template loop does not work

Posted: 25 August 2020, 13:36
by Volker78
Anyone?

Re: Translation in template loop does not work

Posted: 26 August 2020, 09:22
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?

Re: Translation in template loop does not work

Posted: 26 August 2020, 18:07
by Volker78
it is wrapped with to-translate but still not translated, although the translation for that string is available

Re: Translation in template loop does not work

Posted: 30 August 2020, 18:34
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.

Re: Translation in template loop does not work

Posted: 12 December 2020, 21:40
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)

Re: Translation in template loop does not work

Posted: 13 December 2020, 21:54
by Volker78
Thanks, that should answer my question