2017 © Pedro PelĂĄez
 

symfony-bundle translation-form-bundle

Translate your doctrine objects easily with some helps

image

a2lix/translation-form-bundle

Translate your doctrine objects easily with some helps

  • Thursday, July 26, 2018
  • by a2lix
  • Repository
  • 19 Watchers
  • 205 Stars
  • 1,666,854 Installations
  • PHP
  • 38 Dependents
  • 9 Suggesters
  • 102 Forks
  • 2 Open issues
  • 31 Versions
  • 6 % Grown

The README.md

A2lix Translation Form Bundle

Translate your doctrine objects easily with some helps, (*1)

Latest Stable Version Latest Unstable Version License, (*2)

Total Downloads Monthly Downloads Daily Downloads, (*3)

Branch Tools
3.x (master) Build Status Coverage Status

Screenshot example

A2LiX Translation Form Screenshot, (*4)

Support

Installation

Use composer:, (*5)

composer require a2lix/translation-form-bundle

After the successful installation, add/check the bundle registration:, (*6)

// Symfony >= 4.0 in bundles.php
// ...
A2lix\AutoFormBundle\A2lixAutoFormBundle::class => ['all' => true],
A2lix\TranslationFormBundle\A2lixTranslationFormBundle::class => ['all' => true],
// ...

// Symfony >= 3.4 in AppKernel::registerBundles()
$bundles = array(
// ...
new A2lix\AutoFormBundle\A2lixAutoFormBundle(),
new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
// ...

Configuration

There is no minimal configuration. Full list of optional parameters:, (*7)

# Symfony >= 4.0. Create a dedicated a2lix.yaml in config/packages with:
# Symfony >= 3.4. Add in your app/config/config.yml:

a2lix_translation_form:
    locale_provider: default       # [1]
    locales: [en, fr, es, de]      # [1-a]
    default_locale: en             # [1-b]
    required_locales: [fr]         # [1-c]
    templating: "@A2lixTranslationForm/bootstrap_4_layout.html.twig"      # [2]
  1. Custom locale provider service id. Default one relies on [1-*] values:
    • [1-a] List of translations locales to display
    • [1-b] Default locale
    • [1-c] List of required translations locales
  2. The default template is Twitter Bootstrap compatible. You can redefine your own here

Usage

In a classic formType

use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
...
$builder->add('translations', TranslationsType::class);

Advanced examples

use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
...
$builder->add('translations', TranslationsType::class, [
    'locales' => ['en', 'fr', 'es', 'de'],   // [1]
    'default_locale' => ['en'],              // [1]
    'required_locales' => ['fr'],            // [1]
    'fields' => [                               // [2]
        'description' => [                         // [3.a]
            'field_type' => 'textarea',                // [4]
            'label' => 'descript.',                    // [4]
            'locale_options' => [                  // [3.b]
                'es' => ['label' => 'descripciĂłn'],    // [4]
                'fr' => ['display' => false]           // [4]
            ]
        ]
    ],
    'excluded_fields' => ['details'],           // [2]
    'locale_labels' => [                        // [5]
        'fr' => 'Français',
        'en' => 'English',
    ],
]);
  1. Optional. If set, override the default value from config.yml
  2. Optional. If set, override the default value from config.yml
  3. Optional. If set, override the auto configuration of fields
    • [3.a] Optional. - For a field, applied to all locales
    • [3.b] Optional. - For a specific locale of a field
  4. Optional. Common options of symfony forms (max_length, required, trim, read_only, constraints, ...), which was added 'field_type' and 'display'
  5. Optional. Set the labels for the translation tabs. Default to the name of the locale. Translation keys can be used here.

Additional

TranslationsFormsType

A different approach for entities which don't share fields untranslated. No strategy used here, only a locale field in your entity., (*8)

use A2lix\TranslationFormBundle\Form\Type\TranslationsFormsType;
...
$builder->add('translations', TranslationsFormsType::class, [
    'locales' => ['en', 'fr', 'es', 'de'],   // [1]
    'default_locale' => ['en']               // [1]
    'required_locales' => ['fr'],            // [1]
    'form_type' => ProductMediaType::class,     // [2 - Mandatory]
    'form_options' => [                         // [2bis]
         'context' => 'pdf'
    ]
]);
  1. Optional. If set, override the default value from config.yml
  2. Mandatory. A real form type that you have to do
    • [2bis] Optional. - An array of options that you can set to your form

TranslatedEntityType

Modified version of the native 'entity' symfony form type to translate the label in the current locale by reading translations, (*9)

use A2lix\TranslationFormBundle\Form\Type\TranslatedEntityType;
...
$builder->add('medias', TranslatedEntityType::class, [
    'class' => 'A2lix\DemoTranslationBundle\Entity\Media',   // [1 - Mandatory]
    'translation_property' => 'title',                           // [2 - Mandatory]
    'multiple' => true,                                             // [3]
]);
  1. Path of the translatable class
  2. Property/Method of the translatable class that will be display
  3. Common options of the 'entity' Symfony form type (multiple, ...)

Example

See Demo Bundle for more examples., (*10)

Contribution help

docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer install --ignore-platform-reqs
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer run-script phpunit
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer run-script cs-fixer

License

This package is available under the MIT license., (*11)

The Versions

05/08 2016

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

11/04 2016

2.1.2

2.1.2.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with some helps

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

04/02 2016

2.1.1

2.1.1.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with some helps

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

12/01 2016

2.1

2.1.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with some helps

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

02/12 2014

2.0.4

2.0.4.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with some helps

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

10/11 2014

2.0.3

2.0.3.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with some helps

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

12/09 2014

2.0.2

2.0.2.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

27/04 2014

2.0.1

2.0.1.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

17/12 2013

1.3

1.3.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

15/12 2013

2.0.0

2.0.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

The Development Requires

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

07/11 2013

1.2

1.2.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

23/09 2013

1.1

1.1.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

form symfony2 translation doctrine2 i18n translatable internationalization knplabs gedmo

30/07 2013

0.x-dev

0.9999999.9999999.9999999-dev https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

25/07 2013

1.0

1.0.0.0 https://github.com/a2lix/TranslationFormBundle

Translate your doctrine objects easily with a custom form field

  Sources   Download

MIT

The Requires

 

form symfony2 translation doctrine2 translatable knplabs gedmo

15/03 2013

0.4.0

0.4.0.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

22/10 2012

0.3.10

0.3.10.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

26/09 2012

0.3.9

0.3.9.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

15/09 2012

0.3.8

0.3.8.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

13/09 2012

0.3.5

0.3.5.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

20/08 2012

0.3.0

0.3.0.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo

30/07 2012

0.2.0

0.2.0.0 https://github.com/a2lix/TranslationFormBundle

Translation field to use with Translatable Doctrine extension

  Sources   Download

MIT

The Requires

 

form translation doctrine2 translatable gedmo