Page 1 of 1

TPL translation in game.view.php

Posted: 21 May 2020, 21:35
by Mistergos
Hi there

in my game.view.php, i have this :

Code: Select all

$this->tpl['WEATHER_TITLE'] = self::_("Weather token");
In my game_game.tpl, i have this :

Code: Select all

var jstpl_tooltip_weather = '<div class="tooltip-container">\
		<span class="tooltip-title">{WEATHER_TITLE}</span>\
		<hr/>\
		<span class="tooltip-message">{WEATHER_DESCRIPTION}</span>\
	</div>';
In my, javascript i have :

Code: Select all

this.addTooltipHtmlToClass( 'weatherMarker', this.format_block('jstpl_tooltip_weather'));

The string resource appears in the translation center, but my tooltips shows always in english, not translated. What did i miss?

Re: TPL translation in game.view.php

Posted: 22 May 2020, 09:18
by A-dam
Hi,

I dont think you will be ever do translations this way. I believe you can use self::_("Weather token") in view.php and tpl only for rendering static text (defined directly in html in tpl file), not for dynamic javascript constructs.

The easiest way to fix this is:

Code: Select all

var jstpl_tooltip_weather = '<div class="tooltip-container">\
		<span class="tooltip-title">${WEATHER_TITLE}</span>\
		<hr/>\
		<span class="tooltip-message">${WEATHER_DESCRIPTION}</span>\
	</div>';

Code: Select all

this.addTooltipHtmlToClass( 'weatherMarker', 
	this.format_block('jstpl_tooltip_weather'), {
		WEATHER_TITLE: _("Weather token"), 
		WEATHER_DESCRIPTION: _("some text")}
	);
and of course you will delete the line in view.php.

If you , for some reasons want to have those texts defined in php. I would use text definitions in material.inc.php with clienttranslate("some text") and than send those definitions via getAlddDatas function to js.

hope this helps

Adam

Re: TPL translation in game.view.php

Posted: 22 May 2020, 18:36
by Mistergos
Thx. Unfortunate i did not know that before :(

I will change all to your first solution.

Thanks again

Re: TPL translation in game.view.php

Posted: 23 May 2020, 08:30
by LaszloK
In fact you should avoid using server-side translation in view.php altogether and translate on the js side whenever possible. Anything that you translate on the server side will be shown incorrectly during replay (instead of using the language preference of the user viewing the replay, it's going to use the language preference of the user whose point of view was chosen for the replay).