Translating complex state-descriptions

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

Translating complex state-descriptions

Post by Volker78 »

In thurn and taxis have some states like this:

Code: Select all

STATE_ADD_CITY_CARD => array(
		"name" => "addCityCard",
		"description" => clienttranslate('${actplayer} ${mustmay} add a ${second} city card to their hand'),
		"descriptionmyturn" => clienttranslate('${you} ${mustmay} add a ${second} city card to your hand'),
		"type" => "activeplayer",
		"args" => "argAddCityCard",
		"possibleactions" => array("getCard", "replaceCityCards", "pass"),
		"transitions" => array("playCard" => STATE_PLAY_CITY_CARD, "getSecondCard" => STATE_ADD_CITY_CARD, "replaceCityCards" => STATE_ADD_CITY_CARD),
	),
mustmay = must / may
second = second / ''

This way, translating makes problems for many languages.

In the docs I have seen something like:

Code: Select all

					if (args.args.mustmay == 'must')
						if (args.args.second)
							this.gamedatas.gamestate.descriptionmyturn = _('${you} must add a second city card to your hand');
						else
							this.gamedatas.gamestate.descriptionmyturn = _('${you} must add a city card to your hand');
					else
						if (args.args.second)
							this.gamedatas.gamestate.descriptionmyturn = _('${you} may add a second city card to your hand');
						else
							this.gamedatas.gamestate.descriptionmyturn = _('${you} may add a city card to your hand');
					this.gamedatas.gamestate.descriptionmyturn = dojo.string.substitute(this.gamedatas.gamestate.descriptionmyturn, args.args);
        			this.updatePageTitle();
But I am not sure, if here the ${you} won't be translated with the dojo.string.substitute method. Which client-method is used internally for the state-descriptions for translating. Also for highlighting the ${player_name} field? Or do I have to do it manually with inserting some <span style="color..?
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Translating complex state-descriptions

Post by Tisaac »

Hi, this is a recurrent problem, best solution so far that I know is the one I explained here : https://boardgamearena.com/forum/viewto ... 12&t=16788
Let me know if you need more info.
User avatar
fafa-fr
Posts: 383
Joined: 22 December 2013, 21:58

Re: Translating complex state-descriptions

Post by fafa-fr »

Hi,
Volker78 wrote: 04 August 2020, 03:30

Code: Select all

		"descriptionmyturn" => clienttranslate('${you} ${mustmay} add a ${second} city card to your hand'),
mustmay = must / may
second = second / ''

This way, translating makes problems for many languages.
Yes indeed, this kind of single translatable string with arguments modifying the sentence should never be used. Using several different translatable strings is the way to go. Arguments should only be used for things that don't modify the sentence (e.g. type of card, etc.).
Volker78 wrote: 04 August 2020, 03:30 But I am not sure, if here the ${you} won't be translated with the dojo.string.substitute method.
It's not an answer to your main question, but personally I never use the ${you} substitution (coloration), because if the string it is included in is not translated yet by the community, it results in displaying ugly sentences where the "you" is translated (because it is translated site-wide, not in the game strings) and the rest of the sentence is not translated (like "Vous must play a card"). I think that displaying "you" in color is not really important, compared to displaying meaningfull sentences. In real-time games, players know their color, and in turn-based games they can see their color in their player panel.
So I would use "You must add ..." without "${you}" substitution.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Translating complex state-descriptions

Post by Een »

fafa-fr wrote: 04 August 2020, 10:23
Volker78 wrote: 04 August 2020, 03:30

Code: Select all

		"descriptionmyturn" => clienttranslate('${you} ${mustmay} add a ${second} city card to your hand'),
mustmay = must / may
second = second / ''

This way, translating makes problems for many languages.
Yes indeed, this kind of single translatable string with arguments modifying the sentence should never be used. Using several different translatable strings is the way to go. Arguments should only be used for things that don't modify the sentence (e.g. type of card, etc.).
Exactly. Building sentences at the syntactical level through concatenation should be avoided, as it will result in untranslatable structures for some languages. Substitution should be used only for numbers or words separated from the overall structure of the sentence (such as between parenthesis or after a ":")
fafa-fr wrote: 04 August 2020, 10:23 personally I never use the ${you} substitution (coloration), because if the string it is included in is not translated yet by the community, it results in displaying ugly sentences where the "you" is translated (because it is translated site-wide, not in the game strings) and the rest of the sentence is not translated (like "Vous must play a card"). I think that displaying "you" in color is not really important, compared to displaying meaningfull sentences. In real-time games, players know their color, and in turn-based games they can see their color in their player panel.
So I would use "You must add ..." without "${you}" substitution.
That's not recommended. It's true that temporarily while waiting for translations to be available some sentences can be mixed with the "You" being already translated, but it's only temporary, while otherwise, the "You" will never have the colouring.
User avatar
Volker78
Posts: 66
Joined: 29 April 2020, 21:37

Re: Translating complex state-descriptions

Post by Volker78 »

Thanks, I solved it clientside now. And I did not need the dojo-substitute function in this case, because

this.updatePageTitle();

does the substitution magically :-) Perhaps that could be written in the docs.
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

Re: Translating complex state-descriptions

Post by quietmint »

I know Tisaac provided a link, but I'd like to repeat the solution we use in Santorini -- we store all the descriptions in states.inc.php and use JavaScript to swap the description as needed.

Code: Select all

  ST_MOVE => [
    'name' => 'playerMove',
    'description' => clienttranslate('${actplayer} must move'),
    'descriptionskippable' => clienttranslate('${actplayer} may move'),
    'descriptionmyturn' => clienttranslate('${you} must move'),
    'descriptionmyturnskippable' => clienttranslate('${you} may move'),
    'descriptioncannot' => clienttranslate('${you} cannot move'),

Code: Select all

  onEnteringState: function (stateName, args) {
    if (args && args.args && args.args.skippable) {
      this.gamedatas.gamestate.description = this.gamedatas.gamestate.descriptionskippable;
      this.gamedatas.gamestate.descriptionmyturn = this.gamedatas.gamestate.descriptionmyturnskippable;
      this.updatePageTitle();
    }
User avatar
Lymon Flowers
Posts: 196
Joined: 01 April 2020, 21:14

Re: Translating complex state-descriptions

Post by Lymon Flowers »

That is a great solution! I personally used JS to modify the innerHTML of the title, which is less optimal than this. Thanks!
Post Reply

Return to “Developers”