php-translation / symfony-bundle

Symfony integration for Translations
MIT License
327 stars 94 forks source link

Extract with annotation @Translate #402

Closed pdias closed 2 years ago

pdias commented 4 years ago

I try to translate some labels… using annotation.

$builder->add(
            'photoFile',
            VichFileType::class,
            [
                'required' => false,
                'allow_delete' => true, // not mandatory, default is true
                'download_uri' => true, // not mandatory, default is true
                'label' => 'user.photo',
                'help' => 'user.photo.help',
                'help_attr' => ['class' => 'mt-0'],
                'delete_label' => /** @Translate */'user.photo.remove',
                'download_label' => /** @Translate */'user.photo.download',
                'attr' => [
                    'placeholder' => 'user.photo.placeholder',
                    'lang' => $this->locale,
                    'class' => 'btn-light',
                    'accept' => 'image/jpg, image/jpeg, image/png',
                ],
                'translation_domain' => 'My',
            ]
        );

But 'delete_label' => /** @Translate */'user.photo.remove' and 'download_label' => /** @Translate */'user.photo.download' are not extracted. Maybe I'm doing something wrong, but I don't understand what.

axi commented 4 years ago

have you included use Translation\Extractor\Annotation\Translate; ?

pdias commented 4 years ago

Yes.

jeremiegrenier commented 3 years ago

Hello,

I got the same problem. I installed the bundle. Add annotation over the key trad I want to be extracted:

new Metas( 'mission_oid', /* @Translate({"domain"="document"}) */ 'document_metas_oid' );

I found that there is two errors:

First the "Translation\Extractor\Visitor\Php\TranslateAnnotationVisitor" that manage the annotation extracting is not a service and not tagged with the "php_translation.visitor".

So I fix it with :

` services: Translation\Extractor\Visitor\Php\TranslateAnnotationVisitor: tags: