This is a documentation for Board Game Arena: play board games online !

Translations: Skirtumas tarp puslapio versijų

Iš Board Game Arena.
Pereiti į navigaciją Jump to search
50 eilutė: 50 eilutė:
In general, you use clienttranslate:
In general, you use clienttranslate:
* On your states.inc.php, for field "description" and "descriptionmyturn".
* On your states.inc.php, for field "description" and "descriptionmyturn".
<pre>
      "description" => clienttranslate('${card_name}: ${actplayer} must discard 4 identical energies'),
</pre>
* On "material.inc.php", when defining texts for game material that must be displayed on client side.
* On "material.inc.php", when defining texts for game material that must be displayed on client side.
<pre>
$this->card_types = array(
    1 => array(
        'name' => clienttranslate("Amulet of Air"), // Thus, we can use "_( card_name )" on Javascript side.
</pre>
* When sending a notification with "notifyAllPlayers" or "notifyPlayer", for the game log string and all game log arguments that need a translation.
* When sending a notification with "notifyAllPlayers" or "notifyPlayer", for the game log string and all game log arguments that need a translation.
<pre>
    // A game log string with no argument:
    self::notifyAllPlayers( 'pickLibraryCards', clienttranslate("Everyone draw cards from his library"), array() );
</pre>


'''self::_( "my string to translate" ):'''
'''self::_( "my string to translate" ):'''
59 eilutė: 76 eilutė:
Most of the time, you don't need to translate strings on server side, except on the following 3 situations:
Most of the time, you don't need to translate strings on server side, except on the following 3 situations:
* When throwing an exception because the player did a forbidden move.
* When throwing an exception because the player did a forbidden move.
<pre>
// This will display a translatable red message to the player that just do some wrong action:
throw new feException( self::_('You must choose 3 cards'), true);
// ... notice the use of "true" parameter that signal that this exception is "expected". In theory, all exception that are excepted should be translated.
</pre>
* In "yourgame.view.php", when creating the labels for the game interface used in your template (.tpl) file.
* In "yourgame.view.php", when creating the labels for the game interface used in your template (.tpl) file.
* Eventually, in your material.inc.php, if for example you need to use some string elements in your exceptions.
* Eventually, in your material.inc.php, if for example you need to use some string elements in your exceptions.
<pre>
// In material.inc.php, $this->energies[n]['nametr'] has been created with the self::_() method. This we can do this:
throw new feException( self::_("To execute this action you need more: ").' '.$this->energies[$resource_id]['nametr'], true );
</pre>
* Eventually, in your "getAllDatas" PHP method, as the data return by this method is used only by current user.
* Eventually, in your "getAllDatas" PHP method, as the data return by this method is used only by current user.



18:03, 15 sausio 2013 versija

Using BGA Studio, the game you create is ready to be translated to each language by the BGA community. To make this possible, you only need to specify which string must be translated and how to combine them.

How translation works?

When developing your game, all strings must be in English. Strings must be coherent with the English version of the game.

Before the release of the game, BGA team will do the French translation of the game.

After the release of the game, the BGA players community will translate the game in every language.

What should be translated?

Every text that can be visible by the player when the game is running normally. This includes tooltips, texts on cards, error messages, ...

This does NOT include error messages that are not supposed to happened (unexpected errors).

Focus on translating notifications

Usually, translating a website is simple: you just call a function on every string you have to translate, and the string is translated in the player's language. On Board Game Arena, this is exactly the same with the "_( string )" function.

However, there is one difference on BGA: notifications. The server is sending notifications to players, and most of the time the notifications are the same for every players, no matter what language each player is using. This is why notifications are translated on client side in the proper language, even if the strings are defined on server side.

On client side (Javascript)

On client side, things are quite simple: you just have to use the "_()" function for all strings you want to translate.

Examples:

// Get a string in player's language:
var translated = _("original english string");

// Get a string in player's language with parameter:
var translated = dojo.string.substitute( "You can pick ${p} cards and discard ${d}", {
    p: 2,
    d: 4
} );

Note: what is also possible to do is

On server side (PHP)

On PHP side, you can use 3 different functions to specify that a string must be translated.

clienttranslate( "my string to translate" ):

This function is transparent: it will return the original English string without any change. It's only purpose is to mark this string as "must be translated", and to make sure the translated version of the string will be available on client side.

In general, you use clienttranslate:

  • On your states.inc.php, for field "description" and "descriptionmyturn".
      "description" => clienttranslate('${card_name}: ${actplayer} must discard 4 identical energies'),
  • On "material.inc.php", when defining texts for game material that must be displayed on client side.
$this->card_types = array(

     1 => array(
        'name' => clienttranslate("Amulet of Air"), // Thus, we can use "_( card_name )" on Javascript side.
  • When sending a notification with "notifyAllPlayers" or "notifyPlayer", for the game log string and all game log arguments that need a translation.
     // A game log string with no argument:
     self::notifyAllPlayers( 'pickLibraryCards', clienttranslate("Everyone draw cards from his library"), array() );

self::_( "my string to translate" ):

This function returns a string translated in the language of CURRENT user (ie: player who send the request to the server) (be careful, this is NOT the active player).

Most of the time, you don't need to translate strings on server side, except on the following 3 situations:

  • When throwing an exception because the player did a forbidden move.
// This will display a translatable red message to the player that just do some wrong action:
throw new feException( self::_('You must choose 3 cards'), true);

// ... notice the use of "true" parameter that signal that this exception is "expected". In theory, all exception that are excepted should be translated.
  • In "yourgame.view.php", when creating the labels for the game interface used in your template (.tpl) file.
  • Eventually, in your material.inc.php, if for example you need to use some string elements in your exceptions.
// In material.inc.php, $this->energies[n]['nametr'] has been created with the self::_() method. This we can do this:
throw new feException( self::_("To execute this action you need more: ").' '.$this->energies[$resource_id]['nametr'], true );
  • Eventually, in your "getAllDatas" PHP method, as the data return by this method is used only by current user.

totranslate( "my string to translate" ):

This function works exactly like 'clienttranslate', except it tells BGA that the string is not needed on client side.

You should not use this function, except on the following cases:

  • Statistics name in stats.inc.php
  • Option names and option values name in gameoptions.inc.php