Code Monkey home page Code Monkey logo

i18n-form-bundle's Introduction

koff/i18n-form-bundle

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality StyleCI Coverage Status

This bundle is fork of a2lix/TranslationFormBundle, reorganized and optimized to work with symfony flex

Requirements

Installation

composer req koff/i18n-form-bundle

Configuration

Full configuration example

# config/packages/i18n_form.yaml
i18n_form:
    locales: [en, fr, es, de]
    required_locales: [fr]
    excluded_fields: ['id', 'locale', 'translatable']
    form_theme: 'bootstrap_3' # you can use 'bootstrap_3' or 'bootstrap_4' form template

Usage

Basic example

use Koff\Bundle\I18nFormBundle\Form\Type\TranslationsType;
//...
$builder->add('translations', TranslationsType::class);

Advanced example

use Koff\Bundle\I18nFormBundle\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]
]);
  • [1] Optionnal. If set, override the default value from config.yml
  • [2] Optionnal. If set, override the default value from config.yml
  • [3] Optionnal. If set, override the auto configuration of fields
  • [3.a] Optionnal. - For a field, applied to all locales
  • [3.b] Optionnal. - For a specific locale of a field
  • [4] Optionnal. Common options of symfony forms (max_length, required, trim, read_only, constraints, ...), which was added 'field_type' and 'display'

Additional

TranslationsFormsType

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

use Koff\Bundle\I18nFormBundle\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] Optionnal. If set, override the default value from config.yml
  • [2 - Mandatory]. A real form type that you have to do
  • [2bis] Optionnal. - An array of options that you can set to your form

TranslatedEntityType

Modified version of the native 'entity' symfony2 form type to translate the label in the current locale by reading translations

use Koff\Bundle\I18nFormBundle\Form\Type\TranslatedEntityType;
//...
$builder->add('medias', TranslatedEntityType::class, [
    'class' => 'App\Entity\Media',      // [1 - Mandatory]
    'translation_property' => 'text',   // [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' symfony2 form type (multiple, ...)

Credits

All credits goes to David ALLIX and his a2lix/TranslationFormBundle

License

This package is available under the MIT license.

i18n-form-bundle's People

Contributors

adamelso avatar alch avatar bobvandevijver avatar bocharsky-bw avatar craue avatar decoder1 avatar garak avatar gelolabs avatar gonzalovilaseca avatar grizzlylab avatar inshop avatar koemeet avatar krixer avatar lemoinem avatar mablae avatar markitosgv avatar mickaelandrieu avatar mmoreram avatar montabou avatar mweimerskirch avatar raziel057 avatar rvanlaak avatar sadikoff avatar scheb avatar soullivaneuh avatar tobias-93 avatar tristanbes avatar videl avatar webda2l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bocharsky-bw

i18n-form-bundle's Issues

Configuration error message after update to 4.0.5

After updating to v4.0.5 I get the following error message:

In ScalarNode.php line 36:
Invalid type for path "i18n_form.locales.0". Expected scalar, but got array.

My configuration file:

i18n_form:
    locales: [de, en]
    default_locale: de
    required_locales: [de]

When I comment the 'locales' line, the error message changes to:

In ScalarNode.php line 36:
Invalid type for path "i18n_form.required_locales.0". Expected scalar, but got array.

In the previous version the configuration was working without any issues.

Roadmap

Hi all. I need some help with bundle. If you have some time to test it you are welcome! We need to find and fix all bugs and after it, we can start work on new features and optimizations.

My Task list is:

  • More templates for more customization
  • Simplify formField configuration
  • Use Twig autoconfiguration for form template

If you have any suggestions, I'll be happy to hear them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.