Explorar o código

Merge pull request #320 from qrizly/patch-1

Update doc/translatable.md
Gediminas Morkevicius %!s(int64=13) %!d(string=hai) anos
pai
achega
1c25e09cf9
Modificáronse 1 ficheiros con 53 adicións e 0 borrados
  1. 53 0
      doc/translatable.md

+ 53 - 0
doc/translatable.md

@@ -840,3 +840,56 @@ $em->flush();
 This would create translations for english and lithuanian, and for fruits, **ru** additionally.
 
 Easy like that, any suggestions on improvements are very welcome
+
+
+Example code to use Personal Translations with (sonata) i18n Forms:
+
+Suppose you have a Sonata Backend with s asimple form like:
+
+``` php
+    protected function configureFormFields(FormMapper $formMapper)    {
+        $formMapper
+            ->with('General')
+            ->add('title', 'text')
+            ->end()
+            ;
+    }
+```
+
+Then you can turn it into an 118n Form by providing the following changes.
+
+``` php
+    protected function configureFormFields(FormMapper $formMapper)
+    {
+        $formMapper
+            ->with('General')
+                ->add('title', 'translatable_field', array(
+                    'field'                => 'title',
+                    'personal_translation' => 'ExampleBundle\Entity\Translation\ProductTranslation',
+                    'property_path'        => 'translations',
+                ))
+            ->end()
+        ;
+    }
+
+```
+
+To accomplish this you can add the following code in your bundle:
+
+https://gist.github.com/2437078
+
+<Bundle>/Form/TranslatedFieldType.php
+<Bundle>/Form/EventListener/addTranslatedFieldSubscriber.php
+<Bundle>/Resources/services.yml
+
+Then you can change to your needs:
+
+``` php
+                    'field'                => 'title', //you need to provide which field you wish to translate
+                    'personal_translation' => 'ExampleBundle\Entity\Translation\ProductTranslation', //the personal translation entity
+
+```
+
+
+
+