Skip to content
IDMarinas edited this page Oct 2, 2020 · 3 revisions

Translations files

In folder data/translation go all the translation files for the different languages following the following structure:

  • Used .yaml files to store translations.

    • Files are in data/translation/[LOCALE]/[SCOPE]/[DOMAIN].yaml This is de main structure.
      • [LOCALE] It's a folder with the name of the location. The game uses by default languages with two characters. Example "en", "es", "fr"...
      • [SCOPE] It's a folder with name for a scope of file.
        • You can look at the other folders created to get an idea of how they are used. It is mainly for organization and identification of the translation file.

      • [DOMAIN] It is the name of the file with the extension .yaml
      • By default have six scopes:
        • app This is where the translation files from main of game.
        • module This is where the translation files are stored in the modules.
        • navigation This is where the translation files from the navigation menu are stored.
        • page This is where the translation files from the main pages are stored.
        • partial This is where the translation files from partials (Example, deathmessages, taunts).
        • popup This is where the translation files from popup text.
    • The translations are automatically loaded by the translation factory.
      • It is possible to have more scopes besides page, module ... but remember the structure of the folder translation.
    • In addition, scopes can be nested to better organize translation files. Example:
      • You can use this text domain in your module: module-village-navigation, which would be equivalent to the file data/translation/[LOCALE]/module/village/navigation.yaml
      • [LOCALE] is the code of the language to be translated, according to the default language and the language chosen by the user.
  • Example of use of Translator system

    \LotgdTranslator::t('key.key2.key3', ['params' => 'that you need for translation'], 'page-home', 'en')

    • The last parameter (language) en is optional, by default the translation system uses the default language that is configured.
  • Example for yaml file:

    The scheme used is:
         key:
             key2:
                 key3: 'value'
             key4:
                 - 'value1'
                 - 'value2'
             key5:
                 0: 'value3'
                 1: 'value4'
             key6:
                 '0': 'value5'
                 '1': 'value6'
             key7:
                 '00': 'value7'
                 '01': 'value8'
    
    Becomes:
         'key.key2.key3' => 'value',
         'key.key4.0' => 'value1',
         'key.key4.1' => 'value2,
         'key.key5.0' => 'value3,
         'key.key5.1' => 'value4,
         'key.key6.0' => 'value5',
         'key.key6.1' => 'value5',
         'key.key7.00' => 'value7',
         'key.key7.01' => 'value8',
    

Translation Entities - New in 4.2.0

The LoTGD uses a personal translation method, this method requires the creation of a new entity *Translation where all the translations for that entity are stored.

Example of how to translate certain fields of an entity (I'm going to use as an example the entity Creatures)

//-- src/core/Entity/Creatures.php

namespace Lotgd\Core\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;

/**
 * @ORM\Entity
 * @Gedmo\TranslationEntity(class="Lotgd\Core\Entity\CreaturesTranslation")
 */
class Creatures implements Translatable
{
    /**
     * @var int
     *
     * @ORM\Column(name="creatureid", type="integer", nullable=false, options={"unsigned": true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $creatureid;

    /**
     * @var string
     *
     * Add this annotation to mark a field as translatable
     * @Gedmo\Translatable
     *
     * Other annotation
     * @ORM\Column(name="creaturename", type="string", length=50, nullable=true)
     */
    private $creaturename;

    /**
     * @var string
     *
     * @ORM\Column(name="creatureimage", type="string", length=250, nullable=false)
     */
    private $creatureimage = '';

    //-- Omitted some properties

    /**
     * @ORM\OneToMany(targetEntity="CreaturesTranslation", mappedBy="object", cascade={"all"})
     */
    private $translations;

    public function __construct()
    {
        $this->translations = new ArrayCollection();
    }

    public function __toString()
    {
        return (string) $this->getCreatureid();
    }

    public function getTranslations()
    {
        return $this->translations;
    }

    public function addTranslation(CreaturesTranslation $t)
    {
        if (! $this->translations->contains($t))
        {
            $t->setObject($this);
            $this->translations->add($t);
        }
    }

    //-- All other methods
}

Translation entity for Creatures

//-- src/core/Entity/CreaturesTranslation

namespace Lotgd\Core\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;

/**
 * Creatures translations.
 *
 * @ORM\Table(
 *     uniqueConstraints={
 *         @ORM\UniqueConstraint(name="lookup_unique_idx", columns={"locale", "object_id", "field"})
 *     }
 * )
 * @ORM\Entity
 */
class CreaturesTranslation extends AbstractPersonalTranslation
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer", options={"unsigned": true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Creatures", inversedBy="translations", cascade={"all"})
     * @ORM\JoinColumn(name="object_id", referencedColumnName="creatureid", onDelete="CASCADE")
     */
    protected $object;

    /**
     * @var string
     *
     * @ORM\Column(type="text", nullable=true,  options={"collation": "utf8mb4_unicode_ci"})
     */
    protected $content;

    /**
     * Convenient constructor.
     *
     * @param string $locale
     * @param string $field
     * @param string $value
     */
    public function __construct($locale, $field, $value)
    {
        $this->setLocale($locale);
        $this->setField($field);
        $this->setContent($value);
    }

    public function __toString()
    {
        return (string) $this->getContent();
    }
}

Full documentation in: https://github.com/Atlantic18/DoctrineExtensions/blob/v2.4.x/doc/translatable.md

New versions: 5.2.* and newer

Game

New versions: 5.0.* to 5.1.*

Game

Older versions: 4.4.* to 4.12.*

Game

Older versions: 4.3.* and earlier

Game Installation

Game Build

Game Development

Advices/Answers

Clone this wiki locally