TPL translation in game.view.php

Game development with Board Game Arena Studio
Post Reply
User avatar
Mistergos
Posts: 79
Joined: 18 September 2011, 16:59

TPL translation in game.view.php

Post 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?
User avatar
A-dam
Posts: 107
Joined: 28 September 2013, 18:15

Re: TPL translation in game.view.php

Post 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
User avatar
Mistergos
Posts: 79
Joined: 18 September 2011, 16:59

Re: TPL translation in game.view.php

Post by Mistergos »

Thx. Unfortunate i did not know that before :(

I will change all to your first solution.

Thanks again
User avatar
LaszloK
Posts: 36
Joined: 05 January 2018, 19:00

Re: TPL translation in game.view.php

Post 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).
Post Reply

Return to “Developers”