a2lix / TranslationFormBundle

Ease translations with some dedicated Symfony form types
https://a2lix.fr/bundles/translation-form
MIT License
330 stars 140 forks source link

Error with fields option #3

Closed mrcmorales closed 12 years ago

mrcmorales commented 12 years ago

Hello @a2lix

I'm testing this bundle with Admin Sonata Bundle, but when I put field options I have a error.

This is my mapper:

$formMapper ->add('title') ->add('description') ->add('translations', 'translations',array( 'by_reference' => false, 'locales' => array('fr', 'en'), 'fields' => array( // [Optionnal] Fields configurations. If not, auto detection from translatable annotations 'title' => array( 'label' => 'name', // Custom label 'type' => 'textarea' // Custom type : text or textarea. If not, auto detection from doctrine annotations ), 'description' => array( 'display' => false )

        )));

And Symfony give this error:

CRITICAL - Symfony\Component\OptionsResolver\Exception\InvalidOptionsException: The option "fields" does not exist. Known options are: "attr", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_protection", "csrf_provider", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "locales", "mapped", "max_length", "pattern", "post_max_size_message", "property_path", "read_only", "required", "sonata_admin", "sonata_field_description", "translation_domain", "trim", "validation_constraint", "validation_groups", "virtual" (uncaught exception) at /home/marc/workspace/LoPati2/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php line 255

What Can I do ?

Thanks

Regards

a2lix commented 12 years ago

Are you really up to date to the last version? The "fields" option is new. I never use Sonata which don't attract me a lot with its own way to do forms particularly... I'll test maybe later, when i'll have time

mrcmorales commented 12 years ago

@a2lix Sorry I had a old version. I update and now runs perfectly. Sorry again!

Thanks for your good job.

Regards

a2lix commented 12 years ago

Ok fine, no problem :)

mrcmorales commented 12 years ago

@a2lix Sorry, Do you know when I can see examples to how read in DBi n translation fields? Some example ?

I have find filtering with language, or is automatic like sf1 ?

Thanks

Regards

a2lix commented 12 years ago

It's automatic with the locale from the request (see https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/EventListener/LocaleListener.php#L33) Example use : http://symfony.com/doc/master/book/translation.html#book-translation-locale-url You can also use a dedicated bundle as https://github.com/schmittjoh/JMSI18nRoutingBundle

You can also force the locale at a low level directly on the query with https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#overriding-translatable-locale

mrcmorales commented 12 years ago

@a2lix Thanks a lot!

Now works in all languages less english, when route has en , then print ca that is default language. I don't understand because in BD has the en information correctly.

This is my configuration:

a2lix_translation_form: default_locale: ca # [Optionnal] Default to 'en' locales: [en,es,fr, de]

Controller to read:

public function provaAction(){

    $em = $this->getDoctrine()->getEntityManager();
    //$translatableListener->setDefaultLocale('en');
    $consulta = $em->createQuery('SELECT p FROM BlogBundle:Product p WHERE p.id = 2 ');

    $consulta = $consulta->getResult();
    return $this->render('BlogBundle:Default:prova.html.twig', array('pagina' => $consulta));

}

And the template:

{{ pagina[0].title }} {{ pagina[0].description }}

Do you know when is the possble problem ?

Thanks

Regards

a2lix commented 12 years ago

If your default locale is 'ca' (what is this language? Catalan?), have well configured your config.yml with : stof_doctrine_extensions: default_locale: ca ?

See :https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/Resources/doc/index.rst#configure-the-bundle

mrcmorales commented 12 years ago

Thanks, now works well.

I haven't well configured config.yml.

ca is català, official language in Catalunya (Barcelona '92) , region in Espanya.

Regards

mrcmorales commented 12 years ago

@a2lix Sorry,

If normal that if a information about one language not is entered, and then if I enter with url to this language, don't show nothing?

In symfony 1.4 shows default language...

Thanks

Regards

webda2l commented 12 years ago

By default, translation fallback is not enabled by default (https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#default-locale)

StofDoctrineExtensionsBundle let you enable it in your config.yml (https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/DependencyInjection/Configuration.php#L29) with :

stof_doctrine_extensions: translation_fallback: true

mrcmorales commented 12 years ago

@webda2l Thanks works well.

Sorry but in old version of this bundle, I import another twig template to form.

twig: form: resources:

But yesterday I update bundle and now not works my template...

What Can i do?

Thanks

Regards

webda2l commented 12 years ago

You can you update your template with the new change Or, you stay with the previous version, that i have just tag 0.3.0:

Regards.