2017 © Pedro Peláez
 

symfony-bundle translation-bundle

This Bundle provides a translator from Entity

image

sonofwinter/translation-bundle

This Bundle provides a translator from Entity

  • Friday, July 27, 2018
  • by SonOfWinter
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

TranslationBundle

Installation

Open a command console, enter your project directory and execute:, (*1)

$ composer require sonofwinter/translation-bundle

Configuration

You can override sow_translation.available_locales parameter to a new list for set your available lang list default is [ 'en', 'fr', 'es', 'de', 'it' ], (*2)

By default a Translation entity class exists but you can create your translation entity class who extends AbstractTranslation To use it, set the sow_translation.translation_class_name parameter to, (*3)

<parameter key="sow_translation.translation_class_name">App\Entity\YourTranslationClass</parameter>

Usage

Your translated entities must implements Translatable interface Then define translated properties in your entity, (*4)

    /**
     * @var string
     * @Translate(key="firstname")
     */
    private $firstname;

    /**
     * @var string
     * @Translate(key="lastname", setter="setOtherName")
     */
    private $lastname;

You can defined the key property for matching another name, if it's not, the property name is taken by default. The setter property is used if you want to use another setter. A TranslatableConfigurationException is throws if the setter doens't exist., (*5)

New n V0.8

This bundle now require php >= 8.0, (*6)

you can use attribute instead of annotation, (*7)

use SOW\TranslationBundle\Attribute\Translation;

class MyClasse {

    #[Translation(key: "firstname")]
    private string $firstname = '';

    #[Translation(key: "lastname", setter: "setOtherName")]
    private string $lastname = '';
}

By default, the bundle use annotation method, you have to change configuration to use attributes, (*8)

    sow_translation.translation_method: attribute

If you want to override attribute class, don't forget to define it in configuration, (*9)

    sow_translation.attribute_class_name: SOW\TranslationBundle\Attribute\Translation

Translate

You can use some methods for translate an entity :, (*10)

  • translate(Translatable $entity, string $lang) to translate the entity in $lang
  • translateForLangs(Translatable $entity, array $langs) to translate the entity in multiple languages

Set translations

These methods is use for set translations :, (*11)

  • setTranslationForLangAndValue(Translatable $translatable, string $lang, string $key, string $value) to set a single translation
  • setTranslationForLangAndValues(Translatable $translatable, string $lang, array $values) for set multiple values in one lang
  • setTranslations(Translatable $translatable, array $translations) for set multiple translation for multiple languages

Remove translations

These methods is use for remove translations :, (*12)

  • removeByObjectKeyAndLang(Translatable $object, string $key, string $lang) remove a specific translation
  • removeAllForTranslatable(Translatable $object) remove all translation for object
  • removeAllByKey(string $key) remove all translation for property

The Versions

27/07 2018

dev-master

9999999-dev

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

27/07 2018

v0.2.6

0.2.6.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

26/07 2018

v0.2.5

0.2.5.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

26/07 2018

v0.2.4

0.2.4.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

26/07 2018

v0.2.3

0.2.3.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

23/07 2018

v0.2.2

0.2.2.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

23/07 2018

v0.2.1

0.2.1.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

20/07 2018

v0.2.0

0.2.0.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

12/07 2018

v0.1.4

0.1.4.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/07 2018

v0.1.3

0.1.3.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/07 2018

v0.1.2

0.1.2.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/07 2018

v0.1.1

0.1.1.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/07 2018

v0.1.0

0.1.0.0

This Bundle provides a translator from Entity

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc